gpt4 book ai didi

ios - Twitter 与 SLRequest 分享

转载 作者:行者123 更新时间:2023-11-29 10:38:38 29 4
gpt4 key购买 nike

我是 Sam。目前我正在我的应用程序中开发 Twitter 分享。我需要在没有 ComposeController 的情况下实现它。我需要与来自社交框架的 SLRequest 集成。我使用的代码如下

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *twitterAccountType =[accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:twitterAccountType options:NULL completion:^(BOOL granted, NSError *error) {
if (granted) {
NSLog(@"Creating Request");
// Step 2: Create a request
NSArray *twitterAccounts =[accountStore accountsWithAccountType:twitterAccountType];
NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1.0/statuses/update.json"];
NSDictionary *params = @{@"screen_name" : @"naheshsamy",@"include_rts" : @"0",@"trim_user" : @"1",@"count" : @"1"};
SLRequest *request =
[SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:url parameters:params];

// Attach an account to the request
[request setAccount:[twitterAccounts lastObject]];
NSLog(@"Request %@",request);
// Step 3: Execute the request
[request performRequestWithHandler: ^(NSData *responseData,NSHTTPURLResponse *urlResponse,NSError *error) {
if (responseData) {
if (urlResponse.statusCode >= 200 && urlResponse.statusCode < 300) {
NSError *jsonError;
NSDictionary *timelineData = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&jsonError];

if (timelineData) {
NSLog(@"Timeline Response: %@\n", timelineData);
}
else {
// Our JSON deserialization went awry
NSLog(@"JSON Error: %@", [jsonError localizedDescription]);
}
}
else {
// The server did not respond ... were we rate-limited?
NSLog(@"The response status code is %d %@ %@",urlResponse.statusCode,urlResponse.suggestedFilename,error);
}
}
}];
}
else {
// Access was not granted, or an error occurred
NSLog(@"%@", [error localizedDescription]);
}
}];

我总是收到状态 400 错误..任何帮助将不胜感激。问候,山姆P

最佳答案

代码似乎与我使用的相似。他们确实警告过 API 的 1.0 版不再受支持并且可能无法运行。尝试更改为 1.1,看看是否能解决您的问题。

@"https://api.twitter.com/1.1/statuses/update.json"

关于ios - Twitter 与 SLRequest 分享,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25684515/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com