作業を開始する前に、認証トークンを取得する必要があります。これを行うには、ユーザーが開く必要があるリンクを作成し、アプリへのグランドアクセスを作成する必要があります。後で取得するコード魔女でトークンを要求する必要があります。このメカニズムは、https ://developers.google.com/accounts/docs/OAuth2Login で
次のように説明されています。
private const string GetTokenUrl = "https://accounts.google.com/o/oauth2/token";
private new bool Auth(bool needUserCredentionals = true)
{
var dic = new Dictionary<string, string>();
dic.Add("grant_type", "authorization_code");
dic.Add("code", ResponseCode);
dic.Add("client_id", ApplicationId);
dic.Add("client_secret", ApplicationSecret);
dic.Add("redirect_uri", HttpUtility.UrlEncode(AppRedirectUrl));
var str = String.Join("&", dic.Select(item => item.Key + "=" + item.Value).ToArray());
var client = new WebClient();
client.Headers.Add("Content-type", "application/x-www-form-urlencoded");
string s;
try { s = client.UploadString(GetTokenUrl, str); }
catch (WebException) { return false; }
catch (Exception) { return false; }
AuthResponse response;
try { response = JsonConvert.DeserializeObject<AuthResponse>(s); }
catch (Exception) { return false; }
Token = response.access_token;
SessionTime = DateTime.Now.Ticks + response.expires_in;
if (needUserCredentionals)
if (!GetUserInfo()) return false;
return true;
}
public class AuthResponse
{
public string access_token { get; set; }
public string token_type { get; set; }
public long expires_in { get; set; }
}
ResponseCode 「アクセス許可ページ」からユーザーがリダイレクトされた後にキャッチする必要があるコードですが、このメソッドは api 2 だと思います...多分私は間違っています、誰が知っていますか