【问题标题】:Google OAuth HTTP API iOSGoogle OAuth HTTP API iOS
【发布时间】:2014-11-09 20:54:12
【问题描述】:

我正在尝试让 Google OAuth 在 iOS 上运行,以便向 Google Calendar API 发出请求。我目前正在使用此代码将 Google 登录表加载到 UIWebView 并尝试取回访问令牌..

[AISWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/calendar&redirect_uri=%@&response_type=code&client_id=%@",kSharedURI,kClientId]]]];

通过使用 NSString 一次又一次地解析 HTML,我正在设法从出现在这里的文本字段中获取我认为的访问令牌。但是,当我尝试使用我认为是访问令牌的东西来使用 NSMutableURLRequest 发出这个日历请求时,我收到了来自 Google 的回复说

 error = {
      code = 401;
      errors =  (
                  {
            domain = global;
            location = Authorization;
            locationType = header;
            message = "Login Required";
            reason = required;
        }
    );
    message = "Login Required";
};

如果有人有任何想法,他们将不胜感激。谢谢。

【问题讨论】:

  • 您是否对 kSharedURI 进行 url 编码?

标签: ios objective-c api oauth uiwebview


【解决方案1】:

首先请注意,我不熟悉 Google 的 API。

我认为您将 OAuth 数据作为请求中的参数发送。但是他们要求它们作为身份验证标头。您应该使用 NSURLConnection 之类的框架(或 3rd 方框架)来添加这些标头。

请参考:NSURLConnection and Basic HTTP Authentication in iOS 示例

祝你好运

【讨论】:

    猜你喜欢
    • 2021-10-02
    • 2011-06-17
    • 2013-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-07
    • 2015-06-10
    • 2011-10-29
    相关资源
    最近更新 更多