Access user's iOS default Twitter account iOS

旧街凉风 提交于 2019-12-12 06:15:28

问题


I try to access my user's iOS default Twitter account.

I use STTwitter library. The below code used to work fine on my device, but now it's not. The returned "oAuthToken", "oAuthTokenSecret", and "userID" are nil. but it's still working on the simulator

STTwitterAPI *twitter = [STTwitterAPI twitterAPIWithOAuthConsumerName:nil
                                                          consumerKey:@"myConsumerKey"
                                                       consumerSecret:@"myConsumerSecret"];

[twitter postReverseOAuthTokenRequest:^(NSString *authenticationHeader) {

    STTwitterAPI *twitterAPIOS = [STTwitterAPI twitterAPIOSWithFirstAccount];

    [twitterAPIOS verifyCredentialsWithSuccessBlock:^(NSString *username) {

        [twitterAPIOS postReverseAuthAccessTokenWithAuthenticationHeader:authenticationHeader
                                                            successBlock:^(NSString *oAuthToken,
                                                                           NSString *oAuthTokenSecret,
                                                                           NSString *userID,
                                                                           NSString *screenName) {


                                                                // use the tokens...
                                                                self.oAuthToken = oAuthToken;
                                                                self.oAuthTokenSecret = oAuthTokenSecret;

                                                                if(self.oAuthToken && self.oAuthTokenSecret){
                                                                    completionHandler();

                                                                }
                                                                else{

                                                                    ACAccountStore *account = [[ACAccountStore alloc] init];
                                                                    ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];

                                                                    NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];

                                                                    [account renewCredentialsForAccount:[arrayOfAccounts firstObject] completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {

                                                                             [self getUserTwitterDataFromPhoneSettingsInView:view WithCompletionHandler:completionHandler];

                                                                    }];



                                                                }

                                                            } errorBlock:^(NSError *error) {
                                                                // Error

                                                            }];

    } errorBlock:^(NSError *error) {
        // no twitter account
        // user denied access to their account(s)

    }];

} errorBlock:^(NSError *error) {
    // ...

}];

回答1:


For some reason, it turns out that the Twitter account entered in iOS Settings lacks the 'oauth_token' property and may need to be validated again. A possible fix is to go to iOS Settings and setup the account again. Now, I'll try to find a way to detect this state in STTwitter.



来源:https://stackoverflow.com/questions/30307062/access-users-ios-default-twitter-account-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!