I am using Google API I try to insert moments but I get error: Google.GoogleApiException was unhandled Message=An Error occurred, but the error response could not be deserialized Source=Google.Apis ServiceName=tasks
my code:
// Create the service.
var service = new TasksService(new BaseClientService.Initializer()
{
Authenticator = auth
});
TaskLists results = service.Tasklists.List().Execute();
//it's work fine
Moment body = new Moment();
ItemScope target = new ItemScope();
target.Id = "replacewithuniqueforaddtarget";
target.Image = "http://www.google.com/s2/static/images/GoogleyEyes.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.Target.Url = "https://developers.google.com/+/web/snippet/examples/widget";
body.Type = "http://schemas.google.com/AddActivity";
MomentsResource.InsertRequest insert = new MomentsResource.InsertRequest(service, body, "me", MomentsResource.Collection.Vault);
Moment wrote = insert.Execute(); //error here
What you need to do is either set the target URL or set the other metadata inside of the moment body. If you are setting both, you will get an error. The following code should work:
Or the following code:
I just tested the above code with the 1.4 library, this should work in either case.
It's possible that you are not creating a Google+ service client but instead are just creating the Tasks service client and trying to use that. The following boilerplate is a full example that constructs a Google+ service and writes a moment: