4

我为谷歌 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.

下一步我该怎么做?(以下代码适用于谷歌阅读器。)

#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];
}
4

1 回答 1

2

您应该首先了解 oAuth。

通常,第一个链接是授权流程 - 您调用它并获取代码。第二个 URL 是使用从前一个 URL 获得的代码获取令牌。

Explaining how exactly to work with oAuth is out of the scope here, but you have many places you can read and learn.

于 2012-11-01T09:58:45.700 回答