我应该使用什么重定向URI(OAuth 2.0)?

4

我在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];
}
1个回答

2

你需要先学习oAuth相关知识。

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

在这里详细解释如何使用oAuth超出了范围,但你可以阅读和学习很多相关资料。


谢谢您的回答。我正在学习OAuth,但仍然是一个初学者。但是......我已经学了一点关于OAuth的知识,并且有一个大问题。 如果方便的话,您介意回答我的问题吗? - user1702650
我学到了当我的应用程序将用户重定向到授权页面时,我必须发布“客户端密钥”、“范围”和“重定向URI”,以便在用户授权我的应用程序后使用。而我选择了@"xxxxoob"作为重定向URI(正如你所说,我认为这是授权流程工作所需的)。但我仍然遇到了“com.google.HTTPStatus error 404”的错误。除非我使用了错误的URI,否则可能吗? - user1702650
如果你得到了404错误,我相信问题在于授权页面的URL。请尝试重新检查它,确保它是正确的。你可以打开一个新的线程来专门处理这个问题,并在那里粘贴更多信息(比如你尝试调用的URL等)。顺便说一句,如果我的第一个答案有帮助,请随意将其标记为正确答案(就在“0”下面) :-) - OhadR

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接