首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >与SLRequest分享推特

与SLRequest分享推特
EN

Stack Overflow用户
提问于 2014-09-05 11:06:46
回答 1查看 318关注 0票数 1

这是Sam.Currently,我正在开发我的应用程序中的twitter共享,我需要在没有ComposeController.I的情况下实现它,我需要从社会框架中与SLRequest集成。我使用的代码如下

代码语言:javascript
复制
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错误。任何帮助都将不胜感激。你好,Sam.P

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-09-05 12:12:36

这段代码似乎与我所用的相似。他们确实警告说,API的1.0版不再受支持,而且可能不再起作用。尝试将其改为1.1,看看它是否解决了您的问题。

代码语言:javascript
复制
@"https://api.twitter.com/1.1/statuses/update.json"
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25684515

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档