Exemple #1
0
        public IEnumerator GetAccessToken()
        {
            Debug.Log("Start fetching token...");
            tokenFetchStatus = TokenFetchStatus.Fetching;

            var uri =
                string.Format(
                    "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id={0}&client_secret={1}",
                    APIKey, SecretKey);
            var www = UnityWebRequest.Get(uri);

            yield return(www.SendWebRequest());

            if (string.IsNullOrEmpty(www.error))
            {
                Debug.Log(www.downloadHandler.text);
                var result = JsonUtility.FromJson <TokenResponse> (www.downloadHandler.text);
                Token = result.access_token;
                Debug.Log("Token has been fetched successfully");
                tokenFetchStatus = TokenFetchStatus.Success;
            }
            else
            {
                Debug.LogError(www.error);
                Debug.LogError("Token was fetched failed. Please check your APIKey and SecretKey");
                tokenFetchStatus = TokenFetchStatus.Failed;
            }
        }
Exemple #2
0
        /// <summary>
        /// 获取Token
        /// </summary>
        /// <returns></returns>
        public IEnumerator GetAccessToken()
        {
            Debug.Log("开始获取token");
            tokenFetchStatus = TokenFetchStatus.Fetching;

            var uri =
                string.Format(
                    "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id={0}&client_secret={1}",
                    APIKey, SecretKey);
            var www = UnityWebRequest.Get(uri);

            yield return(www.Send());

            if (string.IsNullOrEmpty(www.error))
            {
                Debug.Log(www.downloadHandler.text);
                var result = JsonUtility.FromJson <TokenResponse> (www.downloadHandler.text);
                Token = result.access_token;
                Debug.Log("token 获取成功");
                tokenFetchStatus = TokenFetchStatus.Success;
            }
            else
            {
                Debug.LogError(www.error);
                Debug.LogError("token 获取失败 检查key和密钥");
                tokenFetchStatus = TokenFetchStatus.Failed;
            }
        }