Access Direct Twitter Messages Using SLRequest iOS

I need to access direct messages using SLrequest. I got the secret oAuthToken and oAuthToken Secret using Reverse oAuth of twitter. Now I need to know how to receive direct messages from https://api.twitter.com/1.1/direct_messages.json url. I tried to add oAuthToken and oAuthTokenSecret part of SLRequest, but I get the same error: "This application does not have permission to access or delete your direct messages." What are oAuthToken and oAuthTokenSecret? How to make direct messages work for the application? I changed the access level of the application to "Read, write and direct messages." Help me solve the problem.

+4
source share
2 answers

Here's how to access direct messages for your default iOS Twitter account.

This example uses the STTwitter library, which internally uses SLRequest for phase 2 and the user-processed request for stage 1.

NSString *CONSUMER_KEY = @""; NSString *CONSUMER_SECRET = @""; STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerName:nil consumerKey:CONSUMER_KEY consumerSecret:CONSUMER_SECRET]; [twitter postReverseOAuthTokenRequest:^(NSString *authenticationHeader) { STTwitterAPI *twitterAPIOS = [STTwitterAPI twitterAPIOSWithFirstAccount]; [twitterAPIOS verifyCredentialsWithSuccessBlock:^(NSString *username) { [twitterAPIOS postReverseAuthAccessTokenWithAuthenticationHeader:authenticationHeader successBlock:^(NSString *oAuthToken, NSString *oAuthTokenSecret, NSString *userID, NSString *screenName) { STTwitterAPI *x = [STTwitterAPI twitterAPIWithOAuthConsumerName:nil consumerKey:CONSUMER_KEY consumerSecret:CONSUMER_SECRET oauthToken:oAuthToken oauthTokenSecret:oAuthTokenSecret]; [x verifyCredentialsWithSuccessBlock:^(NSString *username) { [x getDirectMessagesSinceID:nil count:10 successBlock:^(NSArray *messages) { // ... } errorBlock:^(NSError *error) { // ... }]; } errorBlock:^(NSError *error) { // ... }]; } errorBlock:^(NSError *error) { // ... }]; } errorBlock:^(NSError *error) { // ... }]; } errorBlock:^(NSError *error) { // ... }]; 
+6
source

You cannot do this using reverse authentication. Reverse authentication basically gives you access to OAuth tokens at the same access level as the iOS root application, so you can handle twitter on a remote server. It does not use advanced permissions from your Twitter app from the dev portal. As stated on the twitter website, you must use the full OAuth authentication stream, including a pop-up, in order to gain explicit user permission to access direct messages.

-2
source

Source: https://habr.com/ru/post/1494687/


All Articles