【发布时间】:2014-01-31 21:29:18
【问题描述】:
我有一个应用程序,我在其中进行 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.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]);
}
}];
}
}
}];
}
【问题讨论】:
标签: objective-c twitter slrequest