特里皮特 + GTMOAuthViewControllerTouch

发布于 2025-01-05 20:01:36 字数 2673 浏览 1 评论 0原文

我有一个 iPhone 应用程序。我正在尝试使用 GTMOAuthViewControllerTouch 添加 tripit 支持。它使用 4 NSURL:

NSString *myConsumerKey = kTripItAPIKey;        // pre-registered with service
NSString *myConsumerSecret = kTripItAPISecret;  // pre-assigned by service

GTMOAuthAuthentication *auth = [[[GTMOAuthAuthentication alloc] initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1
                                                                            consumerKey:myConsumerKey
                                                                             privateKey:myConsumerSecret] autorelease];

// setting the service name lets us inspect the auth object later to know
// what service it is for
auth.serviceProvider = @"Tripit";

NSURL *requestURL = [NSURL URLWithString:@"https://api.tripit.com/oauth/request_token"];
NSURL *accessURL = [NSURL URLWithString:@"https://api.tripit.com/oauth/access_token"];
NSURL *authorizeURL = [NSURL URLWithString:@"https://m.tripit.com/oauth/authorize"];
NSString *scope = @"https://api.tripit.com/scope";

GTMOAuthAuthentication *auth = [self myCustomAuth];

// set the callback URL to which the site should redirect, and for which
// the OAuth controller should look to determine when sign-in has
// finished or been canceled
//
// This URL does not need to be for an actual web page
[auth setCallback:@"https://api.tripit.com/OAuthCallback"];

// Display the autentication view
GTMOAuthViewControllerTouch *viewController = [[[GTMOAuthViewControllerTouch alloc] initWithScope:scope
                                                                                         language:nil
                                                                                  requestTokenURL:requestURL
                                                                                authorizeTokenURL:authorizeURL
                                                                                   accessTokenURL:accessURL
                                                                                   authentication:auth
                                                                                   appServiceName:@"AppName"
                                                                                         delegate:self
                                                                                 finishedSelector:@selector(viewController:finishedWithAuth:error:)] autorelease];

[[self navigationController] pushViewController:viewController
                                       animated:YES];

我正在阅读官方文档,我发现了请求、访问和授权 URL,但它没有谈论“范围”和 OAuthCallback url ¿当我尝试访问时,我收到来自 Tripit 站点的“访问请求失败”消息。怎么了? :-(

I have a iPhone app. I'm trying to add tripit support using GTMOAuthViewControllerTouch. It use 4 NSURL:

NSString *myConsumerKey = kTripItAPIKey;        // pre-registered with service
NSString *myConsumerSecret = kTripItAPISecret;  // pre-assigned by service

GTMOAuthAuthentication *auth = [[[GTMOAuthAuthentication alloc] initWithSignatureMethod:kGTMOAuthSignatureMethodHMAC_SHA1
                                                                            consumerKey:myConsumerKey
                                                                             privateKey:myConsumerSecret] autorelease];

// setting the service name lets us inspect the auth object later to know
// what service it is for
auth.serviceProvider = @"Tripit";

NSURL *requestURL = [NSURL URLWithString:@"https://api.tripit.com/oauth/request_token"];
NSURL *accessURL = [NSURL URLWithString:@"https://api.tripit.com/oauth/access_token"];
NSURL *authorizeURL = [NSURL URLWithString:@"https://m.tripit.com/oauth/authorize"];
NSString *scope = @"https://api.tripit.com/scope";

GTMOAuthAuthentication *auth = [self myCustomAuth];

// set the callback URL to which the site should redirect, and for which
// the OAuth controller should look to determine when sign-in has
// finished or been canceled
//
// This URL does not need to be for an actual web page
[auth setCallback:@"https://api.tripit.com/OAuthCallback"];

// Display the autentication view
GTMOAuthViewControllerTouch *viewController = [[[GTMOAuthViewControllerTouch alloc] initWithScope:scope
                                                                                         language:nil
                                                                                  requestTokenURL:requestURL
                                                                                authorizeTokenURL:authorizeURL
                                                                                   accessTokenURL:accessURL
                                                                                   authentication:auth
                                                                                   appServiceName:@"AppName"
                                                                                         delegate:self
                                                                                 finishedSelector:@selector(viewController:finishedWithAuth:error:)] autorelease];

[[self navigationController] pushViewController:viewController
                                       animated:YES];

I was reading official documentation and I found request, access and authotize URL but it doesn't talk anything about "scope" and OAuthCallback url ¿?. When I try to access I receive "Access Request Failed" message from Tripit site. What's wrong? :-(

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凤舞天涯 2025-01-12 20:01:36

如果其他人遇到同样的问题,我会回答这个问题。

您需要稍微修改 Google 的项目才能将其与 TripIt 一起使用。 TripIt 希望您发送 oauth_token 以及请求 URL 中的 oauth_callback。记录 UIWebview 正在加载的请求,以准确查看发送到 TripIt 服务器的内容。

在您的情况下,它可能看起来像这样:

https://m.tripit.com/oauth/authorize?oauth_token=<THE TOKEN HERE>

当它应该看起来像这样时:

https://m.tripit.com/oauth/authorize?oauth_token=<THE TOKEN HERE>&oauth_callback=<YOUR CALLBACK URL>

将回调 URL 附加到原始请求,您应该看到登录/授权屏幕加载,而不是“访问请求失败”。

此外,这可能会帮助任何对 TripIt 和 OAuth 1.0 集成感到困惑的人。
http://blog.andydenmark.com/2009/03 /how-to-build-oauth-consumer.html

I will answer this in case anyone else runs into the same problem.

You will need to slightly modify Google's project to use it with TripIt. TripIt is expecting you to send the oauth_token, as well as the oauth_callback in the request url. Log the request that the UIWebview is loading to see exactly what is being sent to the TripIt servers.

In your case, it probably looks like this:

https://m.tripit.com/oauth/authorize?oauth_token=<THE TOKEN HERE>

When it should look like this:

https://m.tripit.com/oauth/authorize?oauth_token=<THE TOKEN HERE>&oauth_callback=<YOUR CALLBACK URL>

Append the callback URL to the original request and you should see the login/authorize screen loading, instead of "Access Request Failed".

Also, this may help anyone confused about integrating with TripIt and OAuth 1.0.
http://blog.andydenmark.com/2009/03/how-to-build-oauth-consumer.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文