【问题标题】:Google Plus API Moment.InsertGoogle Plus API Moment.Insert
【发布时间】:2013-03-15 02:11:36
【问题描述】:

我正在尝试使用 google-api-dotnet-client 进行 moment.insert,并且还在 oauth 请求中包含 request_visible_actions 和 access_type,但我总是遇到异常:

给定的键不在字典中。

这是堆栈跟踪:

   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

下面是 moment.insert 的代码 sn-p:

            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();

谁能帮我解决问题?

【问题讨论】:

  • 这可以被认为是my question here 的副本,因为那里发布了相同的解决方案并且我已经在我自己的答案中记录了它。

标签: google-plus google-api-dotnet-client


【解决方案1】:

您可能正在使用旧版本的库。最新版本可从此处获得:

确保将所有较旧的客户端库依赖项替换为较新的依赖项。您至少应该替换以下现有版本:

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

离线刷新令牌的示例在Google+ Quickstart Demo (C#/.NET)

【讨论】:

  • 谢谢哥们,我得到了你的答案。我下载的库版本较旧。你知道我们如何在没有用户交互的情况下刷新 access_token 吗?
  • 示例添加到答案。
猜你喜欢
  • 1970-01-01
  • 2013-01-02
  • 2013-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-18
  • 2016-12-07
  • 2013-08-18
相关资源
最近更新 更多