0

I am trying this code:

PlusService plus = new PlusService(
       new Google.Apis.Services.BaseClientService.Initializer()
       {
           ApiKey = "AIzaSyDWaaG1Hnjgjgho6PVdefefddsdsC6FlPXv5rommyzCAf0ziHkTo"
       });
Moment body = new Moment();
ItemScope target = new ItemScope();            
           target.Id = "103692090756564666566349707";
target.Description = "The description for the activity";
target.Name = "An example of add activity";
body.Target = target;
body.Type = "http://schemas.google.com/AddActivity";           
MomentsResource.InsertRequest insert = new MomentsResource.InsertRequest(
    plus, 
    body, 
    "1036920323290766566566349707",
MomentsResource.InsertRequest.CollectionEnum.Vault);
var momentsResource = plus.Activities.List(
    "me", 
    ActivitiesResource.ListRequest.CollectionEnum.Public);
Moment wrote = insert.Execute();//Error here

and my scop script is -

$(location).attr('href', 'https://accounts.google.com/o/oauth2/auth?scope=' +
             'https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.login&https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.me&' +
          'state=generate_a_unique_state_value&' +
          'redirect_uri=http://localhost:58925/Home/&' +
          'response_type=code&' +
          'client_id=564565402546260119.apps.googleusercontent.com&' +
          'access_type=offline');

And the error message is- Could not load file or assembly 'Zlib.Portable, Version=1.9.1.9000, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

  • 1
    that's not even close to how you need to do it please read https://developers.google.com/accounts/docs/OAuth2 and try using the google-dotnet- client lib. – Linda Lawton - DaImTo Aug 13 '14 at 12:32

1 Answers1

0

First, you are not authorizing the user to request scopes for Google+. Your service initializer needs to look like:

        UserCredential credential;

        var initializer = new GoogleAuthorizationCodeFlow.Initializer
        {
            ClientSecrets = secrets,
            Scopes = new[] { PlusService.Scope.PlusLogin}
        };
        var flow = new AAGoogleAuthorizationCodeFlow(initializer);
        credential = await new AuthorizationCodeInstalledApp(flow, new LocalServerCodeReceiver()).AuthorizeAsync
            ("user", CancellationToken.None).ConfigureAwait(false);

        // Create the service.
        var service = new PlusService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential
            });

The official way to login with Google+ is demonstrated in the Google+ Quickstart sample. Once you have logged in the user, you will be able to write moments using the C# client library, e.g.:

        Moment body = new Moment();
        ItemScope itemScope = new ItemScope();
        itemScope.Id = "replacewithuniqueforaddtarget";
        itemScope.Image = "http://www.google.com/s2/static/images/GoogleyEyes.png";
        itemScope.Type = "";
        itemScope.Description = "The description for the action";
        itemScope.Name = "An example of add activity";
        body.Object = itemScope;
        body.Type = "http://schema.org/AddAction";
        MomentsResource.InsertRequest insert =
            new MomentsResource.InsertRequest(
                service,
                body,
                "me",
                MomentsResource.InsertRequest.CollectionEnum.Vault);

        Moment wrote = insert.Execute();

        Console.WriteLine("Wrote app activity:\n" + wrote.Result);

If you are trying to do this from a console app, you can start with this GitHub C# Console demo solution.

class
  • 8,621
  • 29
  • 30
  • Thanks for your suggestion, but it is generating some error at line credential = await new AuthorizationCodeInstalledApp(flow, new LocalServerCodeReceiver()).AuthorizeAsync ("user", CancellationToken.None).ConfigureAwait(false); Could not load file or assembly 'Microsoft.Threading.Tasks.Extensions.Desktop, Version=1.0.16.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. – user3351551 Aug 18 '14 at 13:01
  • This is a known issue with BCL / async. See: http://stackoverflow.com/questions/21057052/asp-net-app-crashes-could-not-load-file-or-assembly-microsoft-threading-tasks – class Aug 19 '14 at 18:08