【问题标题】:Changes coming in Version 1.1 of the Twitter API in iPhoneiPhone 中 Twitter API 1.1 版中的变化
【发布时间】:2013-06-20 13:48:05
【问题描述】:

我正在为我的新 iphone 应用程序使用 twitter API 版本 V1.0。我能够使用 API 的 twitters v1.0 成功地做到这一点,并且一切正常。只需向http://api.twitter.com/1/statuses/user_timeline.json?screen_name=userid 发出请求即可检索我需要的所有信息。 由于 v1.0 已被弃用并且 V1.1 要求对每个请求进行身份验证,因此使用此 API 时出现错误的授权错误(HTTP 响应状态:400)。 我需要在我的应用程序中进行哪些更改。如何生成 OAuth 请求标头,我需要注册我的应用程序吗?如何获得新版本的身份验证?

我希望以上内容有意义,任何帮助将不胜感激。

提前致谢。

【问题讨论】:

    标签: iphone twitter version


    【解决方案1】:

    访问https://dev.twitter.com/docs/ios/making-api-requests-slrequest

    https://dev.twitter.com/docs/oauth/xauth

    您可以使用以下方法获得身份验证:

    NSString *base64 = @"基本 NFRLWGlZY3l1aHJ4OVJaUWI5RW5BOmdVMXlvcVV6YzBNZUhUQmFXdVRZU2NtZHlIWDFOZXhwZmxqRE16bm01aw=="; //oauth_consumer_secret,oauth_consumer_key NSURL *urlAPI = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.twitter.com/oauth2/token"]];

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:urlAPI];
    [request setDelegate:self];
    [request setRequestMethod:@"POST"];
    
    [request addRequestHeader:@"Authorization" value:base64];
    
    [request addRequestHeader:@"Content-Type" value:@"application/x-www-form-urlencoded;charset=UTF-8"];
    
    [request setPostValue:@"client_credentials" forKey:@"grant_type"];
    

    作为回应,您将像这样获得您的应用程序的 authtoken

    {"token_type":"bearer","access_token":"AAAAAAAAAAAAAAAAAAAAAMddRQAAAAAAXRP6Axur1RS%2Fv9YFtJ7TijyPAGo%3DpmNowwOGf3dZTHDiH2gnCcv7qNIyGZcyV2IW5YFTBs"}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-16
      • 2013-01-25
      • 1970-01-01
      • 2023-03-10
      • 2018-12-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多