0

我正在使用用于通过 Google oAuth2 机制进行身份验证的 iOS 应用程序。成功验证后,我必须将代码/令牌发送到服务器以处理文件、日历等的同步。
我能够使用谷歌最新的库/框架成功验证身份。
但是经过身份验证后,我得到了可以发送到服务器的令牌/代码。但是当服务器使用代码向谷歌进行身份验证时,它会失败。
有没有其他API来处理这个?

4

1 回答 1

0

这是一个非常广泛的主题 :) 在某些情况下,将令牌数据添加到 URL 就足够了,例如 LinkedIn,例如:

NSString *requestURLString = [@"https://api.linkedin.com/v1/people/~/shares?oauth2_access_token=" stringByAppendingString:@"LI_access_token"];

在某些情况下,向 HTTP POST 请求添加相应的字段是必要的,例如发布 Facebook,例如:

postString = [NSString stringWithFormat:@"\r\n--%@\r\n", boundary];
postString = [postString stringByAppendingString:@"Content-Disposition: form-data; name=\"access_token\"\r\n\r\n"];
postString = [postString stringByAppendingString:FBSession.activeSession.accessTokenData.accessToken];

或者需要向 HTTP-request 标头添加其他字段,例如 SoundCloud,例如:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:requestURL] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:60.0f];
[request setHTTPMethod:@"GET"];
[request setValue:[@"OAuth " stringByAppendingString:self.accessToken] forHTTPHeaderField:@"Authorization"];

尝试通过使用 API 的文档来阐明您的情况。

于 2014-04-02T12:18:17.577 回答