【发布时间】:2013-12-19 16:08:16
【问题描述】:
我想使用 Google API 通过 dot net 将 SharePoint 文档传输到 Google Drive。为此,我想使用这个link Google Quick Start。
我已经跟踪了每一条信息。它在开头说“完成本页其余部分中描述的步骤,大约五分钟后,您将拥有一个简单的云端硬盘应用程序,可以将文件上传到 Google 云端硬盘”,但事实并非如此。
我从昨天开始尝试运行这个示例,但失败了。
// Register the authenticator and create the service
var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET);
var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
看来这个代码示例已经过时了,谷歌API已经升级了。
警告来了
[Obsolete("GoogleAuthenticationServer 不再受支持,它将在 1.7.0-beta 中删除。考虑使用支持 .NET 4、.NET 的新 Google.Apis.Auth NuGet 包用于 Windows 应用商店应用程序, Windows Phone 7.5 和 8 以及可移植类库")]
另一个代码
var service = new DriveService(new BaseClientService.Initializer()
{
Authenticator = auth
});
还有错误
无法将类型“Google.Apis.Authentication.OAuth2.DotNetOpenAuth.NativeApplicationClient”隐式转换为“Google.Apis.Http.IConfigurableHttpClientInitializer”。存在显式转换(您是否缺少演员表?)
然后我在寻找[最新版本示例],在那里我找到了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":"aa@developer.gserviceaccount.com","client_id":"id","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","javascript_origins":["http://localhost:53404/"]}}
现在我可以运行此应用程序,但如前所述出现错误
错误:redirect_uri_mismatch 请求中的重定向 URI:[[http://localhost:2430/authorize/]] 与注册的重定向 URI 不匹配
我真的不知道这个端口号是从哪里来的,这个授权是从哪里来的。正如你在我的 JSON 中看到的,我没有设置任何类似的东西。
我正在使用 VS 2010 SP1 Ultimate 和 Windows 7 home Basic。
我试图提供完整的信息,我的最终目标是在 Google 驱动器中上传文档。
【问题讨论】:
标签: asp.net google-api google-oauth google-openid google-api-dotnet-client