Iphone Tripit+;GTMOAUTHVIEW控制器触摸屏
我有一个iPhone应用程序。我正在尝试使用GTMOAuthViewControllerTouch添加tripit支持。它使用4个NSURL:Iphone Tripit+;GTMOAUTHVIEW控制器触摸屏,iphone,cocoa-touch,ios4,oauth,Iphone,Cocoa Touch,Ios4,Oauth,我有一个iPhone应用程序。我正在尝试使用GTMOAuthViewControllerTouch添加tripit支持。它使用4个NSURL: NSString *myConsumerKey = kTripItAPIKey; // pre-registered with service NSString *myConsumerSecret = kTripItAPISecret; // pre-assigned by service GTMOAuthAuthentication
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,但它没有提到“范围”和OAuthCallbackURL?。当我尝试访问时,我从Tripit网站收到“访问请求失败”的消息。怎么了-(我会回答这个问题,以防其他人遇到同样的问题 您需要稍微修改Google的项目以将其与TripIt一起使用。TripIt希望您发送oauth_令牌,以及请求url中的oauth_回调。记录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>
https://m.tripit.com/oauth/authorize?oauth_token=
当它看起来像这样时:
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>
https://m.tripit.com/oauth/authorize?oauth_token=&oauth_callback=
将回调URL追加到原始请求后,您将看到登录/授权屏幕加载,而不是“访问请求失败”
此外,这可能会帮助那些对与TripIt和OAuth 1.0集成感到困惑的人。