Google maps api 3 授予Google OAuth无效
我试图通过Google的OAuth进行验证,但在建立与他们的API的连接时遇到了问题 我的客户代码:Google maps api 3 授予Google OAuth无效,google-maps-api-3,meteor,oauth,google-api,google-oauth,Google Maps Api 3,Meteor,Oauth,Google Api,Google Oauth,我试图通过Google的OAuth进行验证,但在建立与他们的API的连接时遇到了问题 我的客户代码: 'click #addChannel': function (event) { event.preventDefault(); var userId = Meteor.userId(); var options = { requestPermissions: [ 'https://www.googleapis.com/auth/youtube
'click #addChannel': function (event) {
event.preventDefault();
var userId = Meteor.userId();
var options = {
requestPermissions: [
'https://www.googleapis.com/auth/youtube',
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/youtube.force-ssl',
'https://www.googleapis.com/auth/youtube.readonly',
'https://www.googleapis.com/auth/youtube.upload',
'https://www.googleapis.com/auth/youtubepartner',
'https://www.googleapis.com/auth/youtubepartner-channel-audit',
],
requestOfflineToken: true
};
Google.requestCredential(options, function(token) {
Meteor.call('userAddOauthCredentials', userId, token, function(error, result) {
if (error) {
throw error;
}
console.log(result);
});
});
我的服务器代码:
userAddOauthCredentials: function(userId, token) {
check(userId, String);
check(token, String);
var config = ServiceConfiguration.configurations.findOne({service: 'google'});
if (!config) {
throw new ServiceConfiguration.ConfigError();
}
console.log(token, config);
var endpoint = 'https://accounts.google.com/o/oauth2/token';
var params = {
code: token,
client_id: config.clientId,
client_secret: OAuth.openSecret(config.secret),
redirect_uri: OAuth._redirectUri('google', config),
grant_type: 'authorization_code',
};
try { <------------------------------------------------------ this fails
response = HTTP.post(endpoint, { params: params });
} catch (err) {
throw _.extend(new Error("(first) Failed to complete OAuth handshake with Google. " + err.message),
{response: err.response});
}
if (response.data.error) { // if the http response was a json object with an error attribute
throw new Error("(second) Failed to complete OAuth handshake with Google. " + response.data);
} else {
return {
accessToken: response.data.access_token,
refreshToken: response.data.refresh_token,
expiresIn: response.data.expires_in,
idToken: response.data.id_token
};
}
您必须将变量参数解析为应用程序/x-www-form-urlencoded。请查找下面的代码进行解析,就像我在php中所做的那样
$fields_string="";
foreach($params as $key=>$value)
{
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string, '&');
现在$field_字符串将包含对params数组的解析。请确认,但是您已经生成了自己的clientID和clientSecret,对吗?400个错误通常是由于请求中的参数不正确造成的,因此我建议尝试跟踪导致错误的方法,并确保正确调用该方法。是的,我已经生成了这些错误。另外,生成错误的不是我的应用程序,而是从google Apith返回的。您是否碰巧对google OAuth的查询有任何网络跟踪?另外,你是否从你的客户那里得到了授权码,并且在代码交换过程中看到了错误?我刚刚注意到我在服务器日志中收到了一些奇怪的警告,更新了postany luck发现了吗?我也有同样的问题,几个小时来我一直在努力解决这个问题。发现一些旧的SO帖子说,尽管有命名,但我们需要提供一封服务电子邮件作为客户id。尝试过,但仍然没有成功(这些帖子是2013年发布的,因此特定问题可能已经解决)。
$fields_string="";
foreach($params as $key=>$value)
{
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string, '&');