失败的OAuth对Instagram使用gtm-oauth2
我已经根据“非Google服务”的文档设置了OAuth请求,并且我获得了90%的工作成果。该应用程序带来了Web视图,我可以登录使用我的应用程序正确的访问令牌Instagram的和接受的范围要求,但一旦我接受我收到以下错误请求:失败的OAuth对Instagram使用gtm-oauth2
Error Error Domain=com.google.HTTPStatus Code=400 "The operation couldn’t be completed.
(com.google.HTTPStatus error 400.)" UserInfo=0x6b7ab00 {data=<7b22636f 6465223a 20343030 2c202265 72726f72 5f747970 65223a20 224f4175 74684578 63657074 696f6e22 2c202265 72726f72 5f6d6573 73616765 223a2022 596f7520 6d757374 20696e63 6c756465 20612076 616c6964 20636c69 656e745f 69642c20 20202020 20202020 20202020 72657370 6f6e7365 5f747970 652c2061 6e642072 65646972 6563745f 75726920 70617261 6d657465 7273227d>}
Error data:
{
code = 400;
"error_message" = "You must include a valid client_id, response_type, and redirect_uri parameters";
"error_type" = OAuthException;
}
好像控制器正试图完成对google.com而不是api.instagram.com的OAuth交易。
这里是我的Objective-C代码来设置和调用控制器:
static NSString *const kKeychainItemName = @"Instagram OAuth2";
static NSString *const kClientID = @"xxxxxxxxx"; // Removed for security
static NSString *const kClientSecret = @"xxxxxxxxx"; // Removed for security
static NSString *const authURLString = @"https://api.instagram.com/oauth/authorize/";
static NSString *const tokenURLString = @"https://api.instagram.com/oauth/authorize/";
static NSString *const redirectURI = @"http://google.com/NeverGonnaFindMe/";
...
NSURL *tokenURL = [NSURL URLWithString:tokenURLString];
// Set up the OAuth request
GTMOAuth2Authentication *auth = [GTMOAuth2Authentication
authenticationWithServiceProvider:@"Instagram API"
tokenURL:tokenURL
redirectURI:redirectURI
clientID:kClientID
clientSecret:kClientSecret
];
// Specify the appropriate scope string, if any, according to the service's API documentation
auth.scope = @"basic likes comments relationships";
NSURL *authURL = [NSURL URLWithString:authURLString];
// Display the authentication view
GTMOAuth2ViewControllerTouch *viewController = [[GTMOAuth2ViewControllerTouch alloc]
initWithAuthentication:auth
authorizationURL:authURL
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)
];
// Capture the Cookie to delete later
viewController.browserCookiesURL = [NSURL URLWithString:@"instagram.com/"];
// Now push our sign-in view
[[self navigationController] pushViewController:viewController animated:YES];
解决
https://groups.google.com/forum/?fromgroups#!topic/instagram-api-developers/SUYPX7ZQHhs
这是令牌网址那是不正确的。正确的令牌URL是:https://api.instagram.com/oauth/access_token/
刚刚做出了完全相同的错误,并将我的头部划伤了一段时间;很高兴我找到了这个! – 2012-10-04 12:39:53
很高兴帮助。 – JoshOiknine 2012-10-04 16:21:27
嘿你能跟我分享这个例子plz plz plz吗? – Hiren 2012-07-10 06:31:09
我在我的博客[http://ifjoshrantheworld.com/instagram-oauth-login-for-ios-objective-c](http://ifjoshrantheworld.com/instagram-oauth-login-for-ios- objective-c) – JoshOiknine 2012-07-10 22:51:57
嗨乔希我登录成功,也获得accesstoken,但不知道如何在Instagram中分享图像可以帮助我吗? – Hiren 2012-07-11 04:31:56