【发布时间】:2017-04-03 14:15:55
【问题描述】:
我正在使用这个简单的服务器端代码创建一个 google 身份验证令牌,用于在客户端嵌入视图
private void GenarateGAToken()
{
GoogleCredential credential;
string keyFilePath = Server.MapPath("") + MYKEYFILENAME;
using (Stream stream = new FileStream(keyFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
credential = GoogleCredential.FromStream(stream);
}
string[] scopes = new string[] { AnalyticsService.Scope.Analytics }; credential = credential.CreateScoped(scopes);
try
{
bearer = ((ITokenAccess)credential).GetAccessTokenForRequestAsync().Result;
}
catch (AggregateException ex)
{
throw ex.InnerException;
}
}
我使用页面上的token来授权API
gapi.analytics.ready(function() {
gapi.analytics.auth.authorize({
'serverAuth': {
'access_token': '{{ <%=bearer%> }}'
}
});
但我收到错误 401“无效凭据”:
{"error":{"errors":[{"domain":"global","reason":"authError","message":"Invalid Credentials","locationType":"header","location":"Authorization"}],"code":401,"message":"Invalid Credentials"}}
在https://www.googleapis.com/oauth2/v1/tokeninfo?access_token= 上测试了令牌值 它看起来有效
Google 帐户似乎已正确设置为具有所有必需权限的服务帐户
我在这里错过了什么?
【问题讨论】:
标签: c# google-analytics