2

我想使用Google API使用dot net将SharePoint文档传输到Google Drive。为了实现这一点,我想使用link Google Quick StartGoogle 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驱动器中上传文件。

回答

2

您正在关注的教程使用旧版本的google.apis,这就是为什么你看到不支持。这里有几个关于它如何与新版本的api一起工作的教程。

+0

感谢您的回答DalmTo, 我试过你提供的第一个链接。 它给了我同样的错误,我已发布** BOLD ** 我能够与谷歌的身份验证屏幕connet,但随后问题与重定向uri。 再次将其添加到这里供您参考。 **请求中的重定向URI:http:// localhost:4103/authorize /与注册的重定向URI不匹配** 我真的不知道Google从哪里附加端口号和**授权**字符串。 –

+0

Hi @DaImTo您好,请帮我解决上述REDIRECT URI问题。你的帮助是高度赞赏。 –

+0

重定向URI需要与您在Google apis控制台中设置的相同。 – DaImTo

0

我下载了示例Eyal提及,并在与我自己的应用程序集成之前得到了编译。 .Net需要是4,但它表示支持更高。

0

您必须在Google开发者控制台中设置重定向URI,而不是在您的JSON中。在你的情况下,你会想把它设置为http://localhost:2430/authorize/