Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GoogleWebAuthorizationBroker not found

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'

code

error

enter image description here

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

enter image description here

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

like image 912
Pedro Celso Avatar asked Mar 17 '14 14:03

Pedro Celso


3 Answers

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.

like image 153
Greg L Avatar answered Oct 09 '22 00:10

Greg L


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;
like image 26
Abhishek Dey Avatar answered Oct 08 '22 22:10

Abhishek Dey


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.

like image 38
user1880531 Avatar answered Oct 09 '22 00:10

user1880531