Imgur API перенаправить на дом - PullRequest
0 голосов
/ 10 ноября 2018

Я хочу использовать imgur API в своем приложении для Android. Но у меня проблема с авторизацией. Я хочу получить токен доступа (OAuth2), но перенаправить imgur в / galery (не получайте токен доступа в URL).

Моя функция (с помощью WebView)

private void setImgurWebview() {
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    mWebView.loadUrl(imgur.getUrlOauth2());

    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            Uri uri = Uri.parse(url.replace('#', '?'));

            super.onPageFinished(view, url);
            if (uri.toString().contains("acces_token")) {
                imgur.setTokenAccess(uri.getQueryParameter("access_token"));
            }
        }
    });
}

Мой IMGUR Clas:

package com.example.wilka.epicture;

public class Imgur {

    // API Parameters
    private String clientId; // Client ID Registration (in Imgur.com)
    private String responseType; // Type of API response
    private String state; // Any String for help to the integration

    // Client Parameters
    private String tokenAccess;


    Imgur(String clientId, String responseType, String state) {
        this.clientId = clientId;
        this.responseType = responseType;
        this.state = state;
    }

    String getUrlOauth2() {
        return ("https://api.imgur.com/oauth2/authorize?client_id=" + this.clientId +
                "&response_type=" + this.responseType +
                "&state=" + this.state);
    }

    void setTokenAccess(String tokenAccess) {
        this.tokenAccess = tokenAccess;
    }

    String getTokenAccess() {
        return (this.tokenAccess);
    }
}

В чем проблема? Спасибо!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...