OAuth、Tumblr 和范围

发布于 2024-12-27 02:19:37 字数 2739 浏览 1 评论 0原文

我正在尝试通过 OAuth 和我开始编写的 Mac 应用程序登录 Tumblr。 我下载了gtm-oauth源代码,一切都很好。

我刚开始在视图控制器中使用这段代码:

- (GTMOAuthAuthentication *)myCustomAuth {

    GTMOAuthAuthentication *auth;
    auth = [[[GTMOAuthAuthentication alloc] initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1
                                                        consumerKey:kConsumerKey
                                                         privateKey:kConsumerSecret] autorelease];
    auth.serviceProvider = @"Custom Auth Service";
    return auth;
}
- (void)viewController:(GTMOAuthViewControllerTouch *)viewController
      finishedWithAuth:(GTMOAuthAuthentication *)auth
                 error:(NSError *)error {
    NSLog(@"finishedWithAuth");
    if (error != nil) {
        NSLog(@"failed");
    } else {
        NSLog(@"done");
    }
}


- (void)signInToCustomService {

    GTMOAuthAuthentication *auth = [self myCustomAuth];
    if (auth == nil) {
        NSLog(@"A valid consumer key and consumer secret are required for signing in to Tumblr");
    }
    else
    {
        NSLog(@"Ok auth");
    }

    NSURL *requestURL = [NSURL URLWithString:@"http://www.tumblr.com/oauth/request_token"];
    NSURL *accessURL = [NSURL URLWithString:@"http://www.tumblr.com/oauth/access_token"];
    NSURL *authorizeURL = [NSURL URLWithString:@"http://www.tumblr.com/oauth/authorize"];

    NSString *scope = @"http://api.tumblr.com"; // HERE I DON'T KNOW WHAT TO WRITE

    GTMOAuthViewControllerTouch *viewController;
    viewController = [[[GTMOAuthViewControllerTouch alloc] initWithScope:scope
                                                                language:nil
                                                         requestTokenURL:requestURL
                                                       authorizeTokenURL:authorizeURL
                                                          accessTokenURL:accessURL
                                                          authentication:auth
                                                          appServiceName:@"My App: Custom Service"
                                                                delegate:self
                                                        finishedSelector:@selector(viewController:finishedWithAuth:error:)] autorelease];

    [self presentModalViewController:viewController animated:YES];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self signInToCustomService];
}

但没有任何反应。

- (void)viewController:(GTMOAuthViewControllerTouch *)viewController
      finishedWithAuth:(GTMOAuthAuthentication *)auth
                 error:(NSError *)error;

这个方法永远不会被调用。 也许这是我的范围变量。我不知道我必须为它写哪个值。 感谢您的帮助 !

I'm trying to login to Tumblr via OAuth and a Mac App I begin to code.
I donwloaded gtm-oauth source code, everything is fine.

I just began with this code inside a view controller :

- (GTMOAuthAuthentication *)myCustomAuth {

    GTMOAuthAuthentication *auth;
    auth = [[[GTMOAuthAuthentication alloc] initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1
                                                        consumerKey:kConsumerKey
                                                         privateKey:kConsumerSecret] autorelease];
    auth.serviceProvider = @"Custom Auth Service";
    return auth;
}
- (void)viewController:(GTMOAuthViewControllerTouch *)viewController
      finishedWithAuth:(GTMOAuthAuthentication *)auth
                 error:(NSError *)error {
    NSLog(@"finishedWithAuth");
    if (error != nil) {
        NSLog(@"failed");
    } else {
        NSLog(@"done");
    }
}


- (void)signInToCustomService {

    GTMOAuthAuthentication *auth = [self myCustomAuth];
    if (auth == nil) {
        NSLog(@"A valid consumer key and consumer secret are required for signing in to Tumblr");
    }
    else
    {
        NSLog(@"Ok auth");
    }

    NSURL *requestURL = [NSURL URLWithString:@"http://www.tumblr.com/oauth/request_token"];
    NSURL *accessURL = [NSURL URLWithString:@"http://www.tumblr.com/oauth/access_token"];
    NSURL *authorizeURL = [NSURL URLWithString:@"http://www.tumblr.com/oauth/authorize"];

    NSString *scope = @"http://api.tumblr.com"; // HERE I DON'T KNOW WHAT TO WRITE

    GTMOAuthViewControllerTouch *viewController;
    viewController = [[[GTMOAuthViewControllerTouch alloc] initWithScope:scope
                                                                language:nil
                                                         requestTokenURL:requestURL
                                                       authorizeTokenURL:authorizeURL
                                                          accessTokenURL:accessURL
                                                          authentication:auth
                                                          appServiceName:@"My App: Custom Service"
                                                                delegate:self
                                                        finishedSelector:@selector(viewController:finishedWithAuth:error:)] autorelease];

    [self presentModalViewController:viewController animated:YES];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
    [self signInToCustomService];
}

But nothing happens.

- (void)viewController:(GTMOAuthViewControllerTouch *)viewController
      finishedWithAuth:(GTMOAuthAuthentication *)auth
                 error:(NSError *)error;

This method is never called.
Perhaps this is my scope variable. I don't know which value I have to write for it.
Thanks for your help !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文