我尝试访问用户的 iOS 默认 Twitter 帐户。
我使用 STTwitter 库。下面的代码曾经在我的设备上正常工作,但现在不是。返回的“oAuthToken”、“oAuthTokenSecret”和“userID”为 nil。但它仍在模拟器上工作
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) {
// ...
}];