1

我已经使用 GTMOAuthAuthentication 进行 twitter 身份验证,并且我可以使用以下代码成功登录 twitter..

NSURL *requestURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/request_token"];
NSURL *accessURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/access_token"];
NSURL *authorizeURL = [NSURL URLWithString:@"https://api.twitter.com/oauth/authorize"];
NSString *scope = @"http://api.twitter.com/";
GTMOAuthAuthentication * auth = [self authForTwitter];
[auth setCallback:@"http://www.noop.com/OAuthCallback"];
[auth setCallback:@"http://www.noop.com/OAuthCallback"];
GTMOAuthViewControllerTouch *viewController = [[GTMOAuthViewControllerTouch alloc]   
initWithScope:scope
language:nil 
requestTokenURL:requestURL  
authorizeTokenURL:authorizeURL
accessTokenURL:accessURL
authentication:auth
appServiceName:@"AppName : Twitter"
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];

[self.navigationController pushViewController:viewController animated:YES];

身份验证后我得到了访问令牌。现在我想在 Twitter 上发布文本、图像和 url。如果我使用以下代码,我会得到 410 错误代码

    NSString *body = [NSString stringWithFormat: @"status=thisisatest"];
    NSString *urlStr = @"http://api.twitter.com/1/statuses/update.json";
    NSURL *url = [NSURL URLWithString:urlStr];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"POST"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [request setHTTPBody: [body dataUsingEncoding:NSUTF8StringEncoding]];
    GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher
                                 fetcherWithRequest:request];
    [myFetcher setAuthorizer: auth];
    [myFetcher beginFetchWithCompletionHandler:^(NSData *retrievedData,
                                                 NSError *error)
     {
         if (error != nil)
         {
             NSLog(@"POST error: %@", error);
         }
         else
         {
             NSDictionary *results = [[[[NSString alloc] initWithData:
                                        retrievedData encoding:NSUTF8StringEncoding] autorelease] JSONValue];
             NSLog(@"POST Successful: #%@ @ %@", [results objectForKey:
                                                  @"id"], [results objectForKey: @"created_at"]); 
         } 
     }]; 

谁能告诉我我在这种方法中做错了什么?

提前致谢。

4

1 回答 1

1

使用 1.1 API。现在认为版本 1 已弃用,您也可以在文档中阅读该版本。

https://api.twitter.com/1.1/statuses/update.json 
于 2013-09-13T09:00:22.180 回答