我發現我可以通過OAuth 2.0,當我重定向URI是認證爲「urn:IETF:WG:OAuth的:2.0:OOB」,但用戶被迫複製代碼,然後返回一個活動並將其粘貼到一個字段中。我希望體驗比這更優雅。當重定向URI爲「http:// localhost」的,(即使是返回的接入代碼)我無法換取一個訪問令牌API。這裏是我的交易所代碼:的Oauth 2不能爲接入令牌交換代碼,返回「invalid_grant」
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
0);
nameValuePairs.add(new BasicNameValuePair("client_id",
OAuth2ClientCredentialsMark1.CLIENT_ID));
nameValuePairs.add(new BasicNameValuePair("client_secret",
OAuth2ClientCredentialsMark1.CLIENT_SECRET));
nameValuePairs.add(new BasicNameValuePair("code", accessCode));
nameValuePairs.add(new BasicNameValuePair("grant_type",
"authorization_code"));
nameValuePairs.add(new BasicNameValuePair("redirect_uri",
OAuth2ClientCredentialsMark1.REDIRECT_URI));
//"http://localhost"
String url = "https://accounts.google.com/o/oauth2/token";
//url += URLEncodedUtils.format(nameValuePairs, "utf-8");
Log.d("print", url);
HttpPost hPost = new HttpPost(
url);
hPost.setHeader("content-type", "application/x-www-form-urlencoded");
hPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
該代碼總是返回{ 「錯誤」: 「invalid_grant」}是什麼給了?
我的應用程序是基於樣本@https://github.com/ddewaele/LatitudeOAuth2Sample的,我一直在關注本教程@http://code.google.com/apis/accounts/docs/OAuth2InstalledApp.html
我有同樣的問題。使用Scala而不是Java,但除此之外它是相同的。我使用http:// localhost:9000作爲重定向URI。 – Magnus 2012-03-07 16:23:15
我在安裝的應用程序上面臨OAuth的相同問題。你有沒有解決這個問題?請給出意見。 – Khushboo 2013-02-05 11:28:24