【发布时间】:2014-03-13 10:11:58
【问题描述】:
我现在正在尝试从 Windows Phone 应用程序添加片刻两天,但无法正常工作。没有真正的教程或做过什么...无论如何,从我到目前为止可以登录的各种来源,请求范围(即使由于某种原因没有请求 login.plus 范围),我尝试发布片刻。这是我能够创建的代码
List<string> scopes = new List<string>();
scopes.Add("https://www.googleapis.com/auth/plus.login");
scopes.Add("https://www.googleapis.com/auth/userinfo.email");
var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "<My client ID>",
ClientSecret = "<My Client Secret>"
},
scopes,
"user",
CancellationToken.None);
var initializer = new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "WP Drive Sample Application",
};
var plusService = new PlusService(initializer);
Moment body = new Moment();
ItemScope target = new ItemScope();
target.Id = "<Unique ID>";
target.Image = "http://www.google.com/s2/static/images/GoogleyEyes.png";
target.Type = "";
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(
plusService,
body,
"me",
MomentsResource.InsertRequest.CollectionEnum.Vault);
Moment wrote = await insert.ExecuteAsync();
当我尝试使用 insert.ExecuteAsync(); 时出现此错误
{The service plus has thrown an exception: Google.GoogleApiException: Google.Apis.Requests.RequestError
Unauthorized [401]
Errors [
Message[Unauthorized] Location[ - ] Reason[unauthorized] Domain[global]
]
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Google.Apis.Requests.ClientServiceRequest`1.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at GooglePlus.MainPage.<Test>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__0(Object state)}
经过一番搜索,我发现我无法访问它的问题可能是我没有使用 request_visible_actions。但问题是我不知道如何用我的代码请求它,而且我在互联网上找不到任何可以在我的 windows phone 应用程序中使用的 c sharp 资源。知道如何解决此问题并最终能够从我的应用程序中发布片刻吗?
【问题讨论】:
-
您是否查看了该链接:ikaisays.com/2013/07/19/…。在我看来,您没有启用 API。
-
我启用了 Google+ API
-
你搞定了吗?
-
没有解决。研究了一段时间,但找不到解决方案,所以我放弃了它。当我有时间时,我会尝试再做一次。
标签: c# windows-phone-8 google-plus google-api-dotnet-client