如何在用于集成的iPhone应用程序中停用Twitter帐户

时间:2014-01-13 07:42:58

标签: objective-c twitter slrequest

我有app在哪里进行Twitter集成。

我能够成功推文。

现在,当我想要取消激活时,我正在使用下面。

SLRequest *postRequest1 = [SLRequest requestForServiceType:SLServiceTypeTwitter 
requestMethod:SLRequestMethodPOST URL:
[NSURL URLWithString:@"https://api.twitter.com/1/account/end_session.json"] 
parameters: [NSDictionary dictionaryWithObject:@"" forKey:@"status"]];

问题是不推荐使用API​​,而我在1.1中找不到此方法。

有替代品吗?

另外我注意到当我再次尝试激活时,不会询问权限。它直接发送推文。 仅首次询问推文权限。取消激活后不再重新激活 - 这是Twitter的行为方式吗?

编辑1

我用于所有推文的代码如下......

if ([self userHasAccessToTwitter]) {

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


    // Request access from the user to access their Twitter account
    [account requestAccessToAccountsWithType:accountType options:NULL completion:^(BOOL granted, NSError *error)
     {
         if (granted == YES)
         {

             ///////////////////////////////////////////////
             //           SEND TEXT ONLY                 ///
             ///////////////////////////////////////////////
             [[NSUserDefaults standardUserDefaults] setValue:@"yes" forKey:@"twitterLogin"];
             [[NSUserDefaults standardUserDefaults] synchronize];


             // Populate array with all available Twitter accounts
             NSString *message1 = [NSString stringWithFormat:@"Hi! I am using twitter integration."];
             NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
             if ([arrayOfAccounts count] > 0)
             {
                 //use the first account available
                 ACAccount *acct = [arrayOfAccounts objectAtIndex:0];

                 SLRequest *postRequest1 = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodPOST URL:[NSURL   URLWithString:@"http://api.twitter.com/1.1/statuses/update.json"] parameters:  [NSDictionary dictionaryWithObject:message1 forKey:@"status"]];
                 [postRequest1 setAccount:acct];//set account
                 [postRequest1 performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
                     if(error) {
                         NSLog(@"error == %@", error);
                     } else {
                         NSLog(@"good to go -1- %i", [urlResponse statusCode]);
                     }

                 }];
             }
         }
     }];
}

1 个答案:

答案 0 :(得分:0)

API v1中的

end_session无论如何都无法正常工作。从1.1开始,这个方法被删除了,没有替代方法。用户应决定是否要撤销对其Twitter帐户的应用程序访问权限。您唯一能做的就是删除auth_token