本文介绍了找不到GoogleWebAuthorizationBroker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习C#(为Windows Phone开发),并且正在尝试将我的用户身份验证到Google的帐户中.我正在使用此代码: https://developers.google.com/api-client-库/dotnet/guide/aaa_oauth#wp

im learning C# (to develop for windows phone), and im trying to authenticate my user into Google's account. Im using this code:https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#wp

var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
            new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read),
            new[] { DriveService.Scope.Drive },
            "user",
            CancellationToken.None);

但是,我不知道为什么,我不能使用"GoogleWebAuthorizationBroker".我已经安装了所有引用,并且即时消息使用了所有导入.

But, i dont know why, i can't use 'GoogleWebAuthorizationBroker'. I already installed all the references, and im using all the imports.

运行程序时,我收到了以下两条消息:

When i run my program, i got these two messages:

名称'CancellationToken'在当前上下文中不存在"

'The name 'CancellationToken' does not exist in the current context'

名称'GoogleWebAuthorizationBroker'在当前上下文中不存在"

'The name 'GoogleWebAuthorizationBroker' does not exist in the current context'

更新:

为了最小化我的反馈周期,我从头开始创建了一个新的Windows Phone项目,使用Windows Phone OS 7.1作为目标OS版本,然后在程序包管理器控制台中执行了以下命令:

To minimize my feedback cycle, i created a new windows phone project from the scratch, using windows phone OS 7.1 as my target OS version, then i executed these commands in package manager console:

pm> install-package google.apis -pre
pm> install-package google.apis.drive.v2 -pre

然后,在我的MainPage.xaml.cs文件中,我编写了以下导入文件:

Then, in my MainPage.xaml.cs, i wrote these imports:

using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using System.IO;
using Google.Apis.Drive.v2;
using Google.Apis.Util.Store;
using System.Threading;

最后,我尝试通过IntelliSense简单地调用"GoogleWebAuthorizationBroker",但是我找不到它.因此,作为我的上一个测试,我写了"GoogleWebAuthorizationBroker"来查看Visual Studio是否指出了我的错误并提出了任何解决方案,但是VS只给了我创建新类或新类型的选项.

And, finally i tried to simple call 'GoogleWebAuthorizationBroker' by IntelliSense, but i couldn`t find it. So, as my last test, i wrote 'GoogleWebAuthorizationBroker' to see if Visual Studio point my error and suggest any solution, but VS only gave me the options to create a new class or new type.

最后但并非最不重要的一点是,我正在使用Visual Studio Express 2012 for Windows Phone,不知道它是否会影响...

Last but not least, im using Visual Studio Express 2012 for Windows Phone, dont know if it affects...

UPDATE2:

当我在对象浏览器中扩展Google.Apis.Auth时,找不到找不到的类(GoogleWebAuthorizationBroker),看来我的安装效果不佳...

When i expanded Google.Apis.Auth in Object Browser, i couldn't find the missing class(GoogleWebAuthorizationBroker), it looks like my installation didn't went well...

更新3:

根据NuGet( https://www.nuget.org/packages/Google.Apis ),Google.Apis与Windows Phone 7.5和8.0兼容.正如我在上面所说的,我使用Windows Phone OS 7.1作为目标OS版本,我更新了7.1 SDK,但找不到7.5 SDK,所以我应该使用7.8吗?请记住,我需要为Windows Phone 7.X开发

According to NuGet (https://www.nuget.org/packages/Google.Apis), Google.Apis is compatible with Windows Phone 7.5 and 8.0. As i said up there, im using windows phone OS 7.1 as my target OS version, i updated my 7.1 SDK, but couldn't find 7.5 sdk, so, should i use 7.8? keep in mind that i need to develop for windows phone 7.X

推荐答案

如果像我以前那样正在构建便携式类库"项目,则可能需要手动添加对

If you are building a "portable class library" project, like I was, you may need to manually add a reference to

Google.Apis.Auth.PlatformServices

我不知道为什么在将Google api添加到便携式类库"时将其遗漏,但这就是为我解决的原因.

I don't know why it is left out when adding google apis to a "Portable Class Library", but that's what solved it for me.

这篇关于找不到GoogleWebAuthorizationBroker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-20 15:39
查看更多