我遇到新發布的Google+ API的幾個問題來獲取的訪問令牌......訪問令牌的Google+
我一直在關注documentation,我有一個代碼(「4/blablabla」),但當我發送POST請求獲得一個訪問令牌,我得到一個「(400)錯誤的請求」的響應...
這裏是我的一段代碼:
// We have a request code, now we want an access token
StringBuilder authLink = new StringBuilder();
authLink.Append("https://accounts.google.com/o/oauth2/token");
authLink.AppendFormat("?code={0}", gplusCode);
authLink.AppendFormat("&client_id={0}", myClientId);
authLink.AppendFormat("&client_secret={0}", mySecret);
authLink.AppendFormat("&redirect_uri={0}", myRedirectUri);
authLink.Append("&scope=https://www.googleapis.com/auth/plus.me");
authLink.Append("&grant_type=authorization_code");
OAuthBase oAuth = new OAuthBase();
string normalizedUrl, normalizedRequestParameters;
string oAuthSignature = oAuth.GenerateSignature(new Uri(authLink.ToString()), appKey, appSecret, code, null, HttpMethod.POST.ToString(), oAuth.GenerateTimeStamp(), oAuth.GenerateNonce(), OAuthBase.SignatureTypes.HMACSHA1, out normalizedUrl, out normalizedRequestParameters);
oAuthSignature = oAuth.UrlEncode(oAuthSignature);
// Rebuild query url with authorization
string url = string.Format("{0}?{1}&oauth_signature={2}", normalizedUrl, normalizedRequestParameters, oAuthSignature);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url.ToString());
request.Method = HttpMethod.POST.ToString();
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = 0;
// Send the request and get the response
try
{
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
// Do stuff ...
如果您使用Fiddler(或類似的)來捕獲引發400的請求,它看起來像什麼? – bzlm
我沒有看到你的代碼有問題,它看起來像谷歌是因爲在FireFox和Google chrome中發出這個錯誤而聞名。如果他們有Google Plus開發者論壇,你可以嘗試請求一個答案。 – Keeano
這個問題的標題是無用的 - 它不描述問題或提出問題 –