Google plus google api错误google.GoogleApiException

Google plus google api错误google.GoogleApiException,google-plus,Google Plus,我正在使用谷歌API 我尝试插入瞬间,但出现错误: Google.GoogleApiException未处理 Message=发生错误,但无法反序列化错误响应 Source=Google.api ServiceName=任务 var service = new TasksService(new BaseClientService.Initializer() { Authenticator = auth }); Task

我正在使用谷歌API 我尝试插入瞬间,但出现错误: Google.GoogleApiException未处理 Message=发生错误,但无法反序列化错误响应 Source=Google.api ServiceName=任务

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
我的代码:

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
//创建服务

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

您需要做的是设置目标URL或设置矩体内部的其他元数据。如果同时设置这两个选项,则会出现错误。以下代码应该可以工作:

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
ItemScope target = new ItemScope();
// target.Id = "replacewithuniqueforaddtarget"; // This is optional.
target.Url = "https://developers.google.com/+/web/snippet/examples/widget";

Moment body = new Moment();
body.Target = target;
body.Type = "http://schemas.google.com/AddActivity";

MomentsResource.InsertRequest insert = 
  new MomentsResource.InsertRequest(service, body, "me",
    MomentsResource.Collection.Vault);
Moment wrote = insert.Execute();
或以下代码:

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
ItemScope target = new ItemScope();
target.Id = "replacewithuniqueforaddtarget"; // Optional
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";

Moment body = new Moment();
body.Target = target;
body.Type = "http://schemas.google.com/AddActivity";

MomentsResource.InsertRequest insert = 
  new MomentsResource.InsertRequest(service, body, "me",
    MomentsResource.Collection.Vault);
Moment wrote = insert.Execute();
我刚刚用1.4库测试了上面的代码,这两种情况下都可以

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
您可能不是在创建Google+服务客户端,而是在创建任务服务客户端并尝试使用它。下面的样板是一个完整的示例,它构建了一个Google+服务,并写了一段话:

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
            // Register the authenticator and construct the Plus service
            // for performing API calls on behalf of the user.
            _authState = YOUR_AUTHSTATE_OBJECT;
            AuthorizationServerDescription description =
                GoogleAuthenticationServer.Description;
            var provider = new WebServerClient(description);
            provider.ClientIdentifier = CLIENT_ID;
            provider.ClientSecret = CLIENT_SECRET;
            var authenticator =
                new OAuth2Authenticator<WebServerClient>(
                    provider,
                    GetAuthorization)
                {
                    NoCaching = true
                };
            ps = new PlusService(new BaseClientService.Initializer()
            {
              Authenticator = authenticator
            });

            Moment body = new Moment();
            body.Target = target;
            body.Type = "http://schemas.google.com/AddActivity";

            MomentsResource.InsertRequest insert =
              new MomentsResource.InsertRequest(ps, body, "me",
                MomentsResource.Collection.Vault);
            Moment wrote = insert.Execute();
//注册验证器并构造Plus服务
//用于代表用户执行API调用。
_authState=您的\u authState\u对象;
授权服务器描述=
GoogleAuthenticationServer.Description;
var provider=新的WebServerClient(说明);
provider.ClientIdentifier=客户端\u ID;
provider.ClientSecret=CLIENT\u SECRET;
var验证器=
新OAuth2Authenticator(
供应商,
获取授权)
{
无切齿=正确
};
ps=new-PlusService(new-BaseClientService.Initializer()
{
验证器=验证器
});
力矩体=新力矩();
body.Target=目标;
body.Type=”http://schemas.google.com/AddActivity";
MomentsResource.InsertRequest插入=
新时刻资源。插入请求(ps,正文,“我”,
动量来源、集合、保险库);
写入的力矩=insert.Execute();

尝试启用详细调试:在.net应用程序中出现相同错误。在尝试下一个代码时也会出现此错误:MomentsResource.ListRequest ListRequest=new MomentsResource.ListRequest(服务,“我”,MomentsResource.CollectionEnum.Vault);MomentsFeed momentsList=listRequest.Execute();你能告诉我更多关于你的开发环境的信息吗?您提到了.NET,您使用的是哪种库版本和编程语言?c#form应用程序、framework 4.0、google.API 1.4.0.28227、google.API.Authentication.OAuth2 1.4.0.28223、google.API.plus.v1 1.4.0.28200、google.API.tasks.v1 1.4.0.28200、dotNetOpenAuth 4.0.0.0.11165、,Newtonsoft.Json 4.5.0.0您可能正在使用任务服务客户端而不是Plus服务客户端?我的代码:private IAAuthorizationState GetAuthorization(NativeApplicationClient){String[]reqAuthScopes=new[]{”“};if(_authstate==null){u authstate=新授权状态(reqAuthScopes);Uri requestURL=客户端.RequestUserAuthorization(reqAuthScopes);Uri url=客户端.RequestUserAuthorization(reqAuthScopes);