简体   繁体   English

访问用户的iOS默认Twitter帐户iOS

[英]Access user's iOS default Twitter account iOS

I try to access my user's iOS default Twitter account. 我尝试访问用户的iOS默认Twitter帐户。

I use STTwitter library. 我使用STTwitter库。 The below code used to work fine on my device, but now it's not. 下面的代码曾经在我的设备上可以正常工作,但现在不是。 The returned "oAuthToken", "oAuthTokenSecret", and "userID" are nil. 返回的“ oAuthToken”,“ oAuthTokenSecret”和“ userID”为零。 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) {
    // ...

}];

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. 出于某种原因,事实证明,在“ iOS设置”中输入的Twitter帐户缺少'oauth_token'属性,可能需要再次进行验证。 A possible fix is to go to iOS Settings and setup the account again. 可能的解决方法是转到“ iOS设置”,然后再次设置帐户。 Now, I'll try to find a way to detect this state in STTwitter. 现在,我将尝试找到一种方法来检测STTwitter中的此状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM