Instagram oauth api给出{“ error_message”:“找不到或已经使用了匹配代码。”,“ code”:400,“ error_type”:“ OAuthException”}

问题描述 投票:0回答:1

最初,一切正常。我尚未对代码进行任何更改。 "Get access_token API"的突然Instagram开始给我一个错误。它说

“ error_message”:“找不到匹配代码或已经使用了匹配代码。”

这是我的示例代码,可在webview]中进行授权:]

public class AuthenticationDialog extends Dialog {
    private String TAG = AuthenticationDialog.class.getSimpleName();
    private AuthenticationListener listener;
    private Context context;
    private WebView webView;

   public AuthenticationDialog(@NonNull Context context, AuthenticationListener listener) {
        super(context);

        this.context = context;
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.webview);
        initializeWebView();
    }

    private void initializeWebView() {

        webView = (WebView) findViewById(R.id.webview);
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setLoadWithOverviewMode(true);

        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("https://www.instagram.com/oauth/authorize?app_id="YOUR APP ID"&redirect_uri=https%3A%2F%2Flocalhost%3A8081%2F&scope=user_profile&response_type=code");
        Log.d(TAG, "url: " + url);
        webView.setWebViewClient(new WebViewClient() {

            String access_token;
            boolean authComplete;

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);
                Log.d(TAG, "onPageStarted called");
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                Log.d(TAG, "onPageFinished called");
                if (url.contains("?code=") && !authComplete) {

                    access_token = url;
                    Log.d(TAG, "Unextracted  code  " + access_token);
                    //get the whole token after "=" sign
                    access_token = access_token.replace("https://localhost:8081/?code=","");
                    access_token = access_token.replace("#_","");
                    authComplete = true;
                    Log.d(TAG, "code returned after extraction  " + access_token);
                    listener.onCodeReceived(access_token);
                    webView.clearCache(true);
                    webView.clearHistory();
                    android.webkit.CookieManager cookieManager = CookieManager.getInstance();

                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        // for  >21 devices
                        cookieManager.removeAllCookies(new ValueCallback<Boolean>() {
                            // a callback which is executed when the cookies have been removed
                            @Override
                            public void onReceiveValue(Boolean aBoolean) {
                                Toast.makeText(context,"Cookie removed:",Toast.LENGTH_LONG).show();
                                Log.d(TAG, "Cookie removed: " + aBoolean);
                            }
                        });
                    }
                    else
                    {
                        // for  <21 devices
                        cookieManager.removeAllCookie();
                    }
                    dismiss();
                } else if (url.contains("?error")) {
                    Log.d(TAG, "getting error fetching access token");
                    webView.clearHistory();
                    dismiss();
                } else {
                    Log.d(TAG, "outside both" + url.toString());
                }
            }
        });
    }
}

这是我在重定向URL上看到的内容

未提取的代码

https://localhost:8081/?code=AQAzJTvM7mld9mWZbW3mKpebmI27Ghbg_uTVQmnNkJyWjFVyJyCu9l9Mwrfe3-EJQ2nTggJJ1G2DvPhNFv7uSYCn-Iu_JzUe2dRBjTRUQhrNsIk0hLupsIGyZDbgwD6nVv223QiAqxt6anCUarBl29xDQ28cibFqeHvDQQsQXQ5kf1BZIDXcCDcUDKjak4pOoF0SMSqBLjk_GXovx2TyaWujk00XyNDMF7kmZzvOkU6Okg#_

AuthenticationDialog:提取后返回的代码

AQAzJTvM7mld9mWZbW3mKpebmI27Ghbg_uTVQmnNkJyWjFVyJyCu9l9Mwrfe3-EJQ2nTggJJ1G2DvPhNFv7uSYCn-Iu_JzUe2dRBjTRUQhrNsIk0hLupsIGyZDbgwD6nVv223QiAqxt6anCUarBl29xDQ28cibFqeHvDQQsQXQ5kf1BZIDXcCDcUDKjak4pOoF0SMSqBLjk_GXovx2TyaWujk00XyNDMF7kmZzvOkU6Okg

提取以上代码后,我请求访问令牌] ::

https://api.instagram.com/oauth/access_token?
app_id="YOUR APP ID"
&app_secret="YOUR SECRET KEY"
&grant_type=authorization_code
&redirect_uri=https%3A%2F%2Fwww.google.com%2F
&code=AQAzJTvM7mld9mWZbW3mKpebmI27Ghbg_uTVQmnNkJyWjFVyJyCu9l9Mwrfe3-EJQ2nTggJJ1G2DvPhNFv7uSYCn-Iu_JzUe2dRBjTRUQhrNsIk0hLupsIGyZDbgwD6nVv223QiAqxt6anCUarBl29xDQ28cibFqeHvDQQsQXQ5kf1BZIDXcCDcUDKjak4pOoF0SMSqBLjk_GXovx2TyaWujk00XyNDMF7kmZzvOkU6Okg

最初我是在响应中获取access_token和userid,但现在它开始给我错误

{“ error_type”:“ OAuthException”,“ code”:400,“ error_message”:“找不到或已经使用了匹配代码”}

请让我知道如何解决此问题。我在Google上搜索了很多链接,但没有一个可以帮助我解决这个问题。

需要帮助的人!!

最初,一切正常。我尚未对代码进行任何更改。 Instagram的“ Get access_token API”突然开始给我一个错误。它说“ error_message”:“匹配代码...

android instagram instagram-graph-api
1个回答
0
投票

您为redirect_uri参数设置了不同的值:

© www.soinside.com 2019 - 2024. All rights reserved.