我想使用Google API使用dot net將SharePoint文檔傳輸到Google Drive。爲了實現這一點,我想使用link Google Quick Start。Google Drive API - 示例代碼無效
我跟蹤了每一小段信息。它在開始時指出:「完成本頁其餘部分描述的步驟,並在大約五分鐘內您將有一個簡單的Drive應用程序將文件上傳到Google Drive」,但事實並非如此。
我想從昨天開始運行這個示例,但失敗了。
// Register the authenticator and create the service
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET);
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
所以看起來這個代碼示例已經過時了,Google APIs已經升級了。
這裏談到的警告
[Obsolete("GoogleAuthenticationServer is not supported any more and it's going to be removed in 1.7.0-beta. Consider using the new Google.Apis.Auth NuGet package which supports .NET 4, .NET for Windows Store apps, Windows Phone 7.5 and 8 and Portable Class Libraries as well")]
另一個代碼
var service = new DriveService(new BaseClientService.Initializer()
{
Authenticator = auth
});
和錯誤
Cannot implicitly convert type 'Google.Apis.Authentication.OAuth2.DotNetOpenAuth.NativeApplicationClient' to 'Google.Apis.Http.IConfigurableHttpClientInitializer'. An explicit conversion exists (are you missing a cast?)
然後我一直在尋找[最新發布的樣品]在那裏我找到了source files。 我也無法運行該示例。
這裏我成功通過身份驗證,但後來有錯誤重定向Uri 我的Client_Secrets.JSON的樣子,你可以看到我已經設置默認重定向Uri到http://localhost/
。
{"web":{"auth_uri":"https://accounts.google.com/o/oauth2/auth","client_secret":"secret","token_uri":"https://accounts.google.com/o/oauth2/token","client_email":email","redirect_uris":["http://localhost/"],"client_x509_cert_url":"[email protected]","client_id":"id","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","javascript_origins":["http://localhost:53404/"]}}
現在我可以運行該應用程序,但如前所述得到錯誤
Error: redirect_uri_mismatch The redirect URI in the request: [[ http://localhost:2430/authorize/]] did not match a registered redirect URI
我真的不從哪裏此端口號來,從這個地方來授權認識。正如你在我的JSON中看到的,我沒有設置任何類似的東西。
我正在使用VS 2010 SP1旗艦版和Windows 7家庭基本版。
我試圖給出完整的信息,我的最終目標是在Google驅動器中上傳文件。
感謝您的回答DalmTo, 我試過你提供的第一個鏈接。 它給了我同樣的錯誤,我已發佈** BOLD ** 我能夠與谷歌的身份驗證屏幕connet,但隨後問題與重定向uri。 再次將其添加到這裏供您參考。 **請求中的重定向URI:http:// localhost:4103/authorize /與註冊的重定向URI不匹配** 我真的不知道Google從哪裏附加端口號和**授權**字符串。 –
Hi @DaImTo您好,請幫我解決上述REDIRECT URI問題。你的幫助是高度讚賞。 –
重定向URI需要與您在Google apis控制檯中設置的相同。 – DaImTo