GoogleWebAuthorizationBroker not found

我的未来我决定 提交于 2019-12-05 00:14:30

问题


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);

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:

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

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

UPDATE:

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

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;

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.

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

UPDATE2:

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...

UPDATE 3:

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


回答1:


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

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.




回答2:


Use these:

in package manager.

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

then include:

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;



回答3:


I had the error GoogleWebAuthorizationBroker not found and I fixed by removing the reference to: Google.Apis.Auth.PlatformServices from my project and Going to the folder where I had all google api assemblies and added ....\packages\Google.Apis.Auth.1.8.1\lib\net40\Google.Apis.Auth.PlatformServices.dll

To the project. I believe I had the wrong assembly.



来源:https://stackoverflow.com/questions/22456668/googlewebauthorizationbroker-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!