我在Google API控制台上注册了我的应用程序。我得到了客户端密钥、客户端ID和两个重定向URI。
//● urn:xxxxxxx:oob
//● http://localhostxxxxxx
当然,我使用这些项目并成功请求了谷歌令牌。但是当我点击授权按钮(比如“您想授权此应用程序吗?”是),会出现两个响应。
如果我使用urnxxxxxx,则会出现“操作无法完成。(com.google.HTTPStatus错误404。)”。
//Or If I use http://localhostxxxxxxxxxxxxx and click Yes button, then nothing
happens.
我该怎么办?(以下代码适用于Google阅读器。)
#import "MasterViewController.h"
#import "DetailViewController.h"
#import "GTMOAuth2Authentication.h"
#import "GTMOAuth2ViewControllerTouch.h"
#import "GTMOAuth2WindowController.h"
static NSString *const kKeychainItemName = @"Greader";
@interface MasterViewController () {
NSMutableArray *_objects;
}
@end
@implementation MasterViewController
- (IBAction)authentication:signInToGoogle:(id)sender;
{}
- (GTMOAuth2Authentication * ) authForGoogle
{
NSString * url_string = @"http://www.google.com/reader/api/";
NSURL * tokenURL = [NSURL URLWithString:url_string];
NSString * redirectURI = @"xxxxoob";
GTMOAuth2Authentication * auth;
auth = [GTMOAuth2Authentication authenticationWithServiceProvider:@"reader"
tokenURL:tokenURL
redirectURI:redirectURI
clientID:@"xxxxx"
clientSecret:@"xxxx"];
auth.scope = @"http://www.google.com/reader/api/";
return auth;
}
- (void)signInToGoogle
{
GTMOAuth2Authentication * auth = [self authForGoogle];
NSString* auth_string = @"https://accounts.google.com/o/oauth2/auth";
NSURL * authURL = [NSURL URLWithString:auth_string];
GTMOAuth2ViewControllerTouch * viewController;
viewController = [[GTMOAuth2ViewControllerTouch alloc]initWithAuthentication:auth
authorizationURL:authURL
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
[self.navigationController pushViewController:viewController animated:YES];
}