Beispiel #1
0
    IEnumerator GetToken()
    {
        string authorizationUrl = settings.tokenUrl;

        WWWForm form = new WWWForm();

        form.AddField("client_id", clientId);
        form.AddField("client_secret", clientSecret);
        form.AddField("grant_type", "pin");
        form.AddField("pin", pin);

        using (UnityWebRequest wr = UnityWebRequest.Post(authorizationUrl, form))
        {
            yield return(wr.SendWebRequest());

            if (!wr.isHttpError || !wr.isNetworkError)
            {
                Debug.Log(wr.downloadHandler.text);
                string json = wr.downloadHandler.text;
                returnAuth = JsonUtility.FromJson <TokenReturn>(json);

                if (!string.IsNullOrEmpty(returnAuth.access_token))
                {
                    returnAuth.success = true;
                    returnAuth.status  = (int)wr.responseCode;
                }
            }
            else
            {
                Debug.LogError(wr.error);
            }
        }
    }
Beispiel #2
0
    void checkState()
    {
        if (checkKey())
        {
            settings.appState = (ImgurSettings.AppState)PlayerPrefs.GetInt("AppState");
        }
        else
        {
            settings.appState = ImgurSettings.AppState.getAuthorization;
        }

        string url = settings.authorizationBaseUrl + settings.clientId + settings.authorizationExtUrl + "pin";

        switch (settings.appState)
        {
        case ImgurSettings.AppState.getAuthorization:
            if (settings.appState == ImgurSettings.AppState.getAuthorization)
            {
                Application.OpenURL(url);
                nextState();
            }

            break;

        case ImgurSettings.AppState.getToken:
            if (PlayerPrefs.HasKey("UserToken"))
            {
                string json = PlayerPrefs.GetString("UserToken");
                returnAuth = JsonUtility.FromJson <TokenReturn>(json);
            }
            else
            {
                settings.appState = ImgurSettings.AppState.getAuthorization;
                Application.OpenURL(url);
            }
            break;

        case ImgurSettings.AppState.authorized:
            if (PlayerPrefs.HasKey("UserToken"))
            {
                string json = PlayerPrefs.GetString("UserToken");
                returnAuth = JsonUtility.FromJson <TokenReturn>(json);
            }
            else
            {
                Debug.LogError("no user token");
                settings.appState = ImgurSettings.AppState.getAuthorization;
                Application.OpenURL(url);
            }

            break;
        }

        PlayerPrefs.SetInt("AppState", (int)settings.appState);
        // settings.appState =(ImgurSettings.AppState)PlayerPrefs.GetInt("AppState");
    }