簡體   English   中英

Twitter與SLRequest分享

[英]Twitter share with SLRequest

是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錯誤的消息。任何幫助將不勝感激。 此致Sam.P

該代碼似乎與我所使用的相似。 他們確實警告說該API的1.0版已不再受支持並且可能無法運行。 嘗試更改為1.1,看看是否可以解決您的問題。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM