3

I am trying for moment.insert using google-api-dotnet-client and also included the request_visible_actions and access_type in oauth request but I am always getting exception:

The given key was not present in the dictionary.

Here is the stack trace:

   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Google.Apis.Discovery.BaseService.GetResource(IResource root, String fullResourceName) in c:\code.google.com\google-api-dotnet-client\default\Tools\BuildRelease\bin\Debug\12-20-2012\default\Src\GoogleApis\Apis\Discovery\Service.cs:line 279
   at Google.Apis.Discovery.BaseService.CreateRequest(String resource, String methodName) in c:\code.google.com\google-api-dotnet-client\default\Tools\BuildRelease\bin\Debug\12-20-2012\default\Src\GoogleApis\Apis\Discovery\Service.cs:line 186
   at Plus.v1.PlusService.CreateRequest(String resource, String method)
   at Google.Apis.Requests.ServiceRequest`1.BuildRequest() in c:\code.google.com\google-api-dotnet-client\default\Tools\BuildRelease\bin\Debug\12-20-2012\default\Src\GoogleApis\Apis\Requests\ServiceRequest.cs:line 134
   at Google.Apis.Requests.ServiceRequest`1.GetAsyncResponse(Action`1 responseHandler) in c:\code.google.com\google-api-dotnet-client\default\Tools\BuildRelease\bin\Debug\12-20-2012\default\Src\GoogleApis\Apis\Requests\ServiceRequest.cs:line 169
   at Google.Apis.Requests.ServiceRequest`1.GetResponse() in c:\code.google.com\google-api-dotnet-client\default\Tools\BuildRelease\bin\Debug\12-20-2012\default\Src\GoogleApis\Apis\Requests\ServiceRequest.cs:line 185
   at Google.Apis.Requests.ServiceRequest`1.Fetch() in c:\code.google.com\google-api-dotnet-client\default\Tools\BuildRelease\bin\Debug\12-20-2012\default\Src\GoogleApis\Apis\Requests\ServiceRequest.cs:line 211
   at VocalbeeWebApp.Controllers.HomeController.CheckGooglePlusAuthorization() in d:\Projects\VocalBee\VocalBeeSocialServer-T\VocalbeeWebApp\VocalbeeWebApp\Controllers\HomeController.cs:line 217

Below is the code snippet for moment.insert:

            Google.Apis.Plus.v1.Data.Moment body = new Google.Apis.Plus.v1.Data.Moment();
            Google.Apis.Plus.v1.Data.ItemScope target = new Google.Apis.Plus.v1.Data.ItemScope();

            target.Id = "target-id";
            target.Image = "http://www.vocalbee.com/Images/WebLogoNewSmall.png";
            target.Type = "http://schemas.google.com/AddActivity";
            target.Description = "The description for the activity";
            target.Name = "An example of add activity";

            body.Target = target;
            body.Type = "http://schemas.google.com/AddActivity";
            Google.Apis.Plus.v1.MomentsResource.InsertRequest insert =
                new Google.Apis.Plus.v1.MomentsResource.InsertRequest(
                    pw.plusService,
                    body,
                    me.Id,
                    Google.Apis.Plus.v1.MomentsResource.Collection.Vault);
            Google.Apis.Plus.v1.Data.Moment result = insert.Fetch();

Can anybody help me in figuring out the problem?

madth3
  • 7,275
  • 12
  • 50
  • 74
rupesh
  • 71
  • 1
  • 8
  • This can be considered a duplicate of [my question here](http://stackoverflow.com/questions/15263378/google-insert-moment-using-google-api-dotnet-client) given that the same solution is posted there and I've documented it in my own answer. – von v. Mar 15 '13 at 23:45

1 Answers1

3

It looks like you might be using an older version of the library. The latest version is available from here:

Make sure that you replace all of the older client library dependencies with the newer ones. You should at least replace existing versions of:

  • Google.Apis.dll
  • Google.Apis.Plus.v1.dll

An example of refreshing the tokens offline is in the Google+ Quickstart Demo (C#/.NET)

class
  • 8,621
  • 29
  • 30
  • Thanks buddy, I got it working with your answer. The version of library I downloaded was older. Do you have any idea how we can refresh the access_token without user interaction? – rupesh Mar 15 '13 at 13:15
  • Example added to answer. – class Jul 31 '13 at 16:16