Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – Oauth 2无法交换访问令牌的代码,返回“invalid_grant”大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我发现当我的重定向uri为“urn:ietf:wg:oauth:2.0:oob”时,我可以通过OAuth 2.0进行身份验证,但是用户被迫复制@L_616_2@,然后返回一个活动并将其粘贴到领域.我希望体验比这更优雅.当重定向uri是“http:// localhost”时,(即使返回了访问@L_616_2@)我也无法将其替换为api的访问令牌.这是我的交换@L_616_2@:

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));

此@L_616_2@始终返回{Error”:“invalid_grant”}给出了什么?

我的应用程序基于样本@ https://github.com/ddewaele/LatitudeOAuth2Sample,我一直在关注教程@ http://code.google.com/apis/accounts/docs/OAuth2InstalledApp.html

解决方法

看来您的@L_616_2@是正确的.该错误来自 OAuth2 spec section-5.2.

最有可能的是,您的应用程序尚未得到用户的授权.

回答你关注的问题:

你能澄清一下oauth2 flow (scenario),你在开发什么?

大佬总结

以上是大佬教程为你收集整理的android – Oauth 2无法交换访问令牌的代码,返回“invalid_grant”全部内容,希望文章能够帮你解决android – Oauth 2无法交换访问令牌的代码,返回“invalid_grant”所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。