Iphone GTM OAuth2通过密钥链检索访问令牌未成功
我下面是谷歌关于如何授权应用程序访问一个或多个API的例子。 问题是,当我成功授权时,我获得了访问令牌,但在此之后,我无法从存储在其中的钥匙链中获取它。我在某个地方读到,iPhone模拟器不能使用钥匙链,是因为这个吗?如果是的话,你能告诉我存储我的访问令牌的其他方法吗 这是我的密码:Iphone GTM OAuth2通过密钥链检索访问令牌未成功,iphone,cocoa-touch,oauth-2.0,Iphone,Cocoa Touch,Oauth 2.0,我下面是谷歌关于如何授权应用程序访问一个或多个API的例子。 问题是,当我成功授权时,我获得了访问令牌,但在此之后,我无法从存储在其中的钥匙链中获取它。我在某个地方读到,iPhone模拟器不能使用钥匙链,是因为这个吗?如果是的话,你能告诉我存储我的访问令牌的其他方法吗 这是我的密码: static NSString *const kKeychainItemName = @"OAuthGoogleReader"; GTMOAuth2Authentication *auth;
static NSString *const kKeychainItemName = @"OAuthGoogleReader";
GTMOAuth2Authentication *auth;
auth = [GTMOAuth2ViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName
clientID:kClientID
clientSecret:kClientSecret];
BOOL isSignedIn = [auth canAuthorize];
if (isSignedIn) {
NSLog(@"Signed");
self.window.rootViewController = self.viewController;
auth.accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"accessToken"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.google.com/reader/api/0/subscription/list?access_token=%@", [auth accessToken]]]];
GTMHTTPFetcher* myFetcher = [GTMHTTPFetcher fetcherWithRequest:request];
// optional upload body data
//[myFetcher setPostData:[postString dataUsingEncoding:NSUTF8StringEncoding]];
[myFetcher setAuthorizer:auth];
[myFetcher beginFetchWithDelegate:self
didFinishSelector:@selector(myFetcher:finishedWithData:error:)];
// - (void)myFetcher:(GTMHTTPFetcher *)fetcher finishedWithData:(NSData *)retrievedData error:(NSError *)error;
}else{
NSString *scope = @"https://www.google.com/reader/api/";
GTMOAuth2ViewControllerTouch *viewController;
viewController = [[GTMOAuth2ViewControllerTouch alloc] initWithScope:scope
clientID:kClientID
clientSecret:kClientSecret
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
self.window.rootViewController = viewController;
}
我得到一个错误:
2012-08-22 16:54:47.253 greader[20833:c07] Signed
2012-08-22 16:54:47.705 greader[20833:c07] Cannot authorize request with scheme http (<NSMutableURLRequest http://www.google.com/reader/api/0/subscription/list?access_token=(null)>)
2012-08-22 16:54:47.253格雷德尔[20833:c07]签名
2012-08-22 16:54:47.705 greader[20833:c07]无法使用方案http()授权请求
正如您所看到的,access_令牌为零
还有一些关于如何使用这个库的简单例子会很好
谢谢大家! gtm-oauth2库负责存储和检索密钥链上的访问令牌和其他身份验证值。应用程序不应该直接使用访问令牌字符串,也不应该将授权令牌放入NSUserDefaults,因为这不够安全
默认情况下,gtm-auth2也将拒绝使用http:scheme将访问令牌附加到URL。OAuth 2仅在与https:scheme URL一起使用时才是安全的。gtm-OAuth 2库负责存储和检索密钥链上的访问令牌和其他身份验证值。应用程序不应该直接使用访问令牌字符串,也不应该将授权令牌放入NSUserDefaults,因为这不够安全
默认情况下,gtm-auth2也将拒绝使用http:scheme将访问令牌附加到URL。OAuth 2仅在与https:scheme URL一起使用时才是安全的。谢谢。我还在使用另一个API—存储访问令牌的最佳位置是什么?您应该如何检索访问令牌以在REST API调用中使用?谢谢。我还在使用另一个API—存储访问令牌的最佳位置是什么?您应该如何检索访问令牌以在REST API调用中使用?