2013-06-27 112 views
0

我跟着this guide使用Google OAuth 2.0授權,但我無法理解如何實現在我的應用程序中檢索訪問和刷新令牌的請求。該代碼,作爲指導說的,是當前:WP7 C#檢索Google OAuth 2.0請求的訪問令牌

// Request an access token  
OAuthAuthorization authorization = new OAuthAuthorization(
"https://accounts.google.com/o/oauth2/auth", 
"https://accounts.google.com/o/oauth2/token"); 
TokenPair tokenPair = await authorization.Authorize(
     ClientId, 
     ClientSecret, 
     new string[] {GoogleScopes.CloudPrint, GoogleScopes.Gmail}); 


// Request a new access token using the refresh token (when the access token was expired) 
TokenPair refreshTokenPair = await authorization.RefreshAccessToken(
     ClientId, 
     ClientSecret, 
     tokenPair.RefreshToken); 

在哪裏,我怎麼可以調用這個函數在一個通用的Windows Phone應用程序?

(很抱歉,如果有這個問題,這是重複的,但我嘗試搜索,我只覺得作爲答案的鏈接通用谷歌蜜蜂指南)

回答

1

你調用它時,它是必要的(當你需要得到令牌)。之後,使用官方Google庫來訪問API並從TokenPair提供數據。另外,記得在你的項目中獲得這個(https://github.com/pieterderycke/MobileOAuth/blob/master/MobileOAuth/GoogleScopes.cs),所以你可以使用GoogleScopes。

+0

嗯,我試圖編譯我的Youtube應用程序與PCL官方Dotnet庫,但每次它無法在啓動時運行....我不知道是否與Windows Phone 7的問題或其他原因.. –

+0

你會得到任何信息是什麼樣的例外嗎? – androphone

相關問題