2016-04-25 86 views
1

我使用Meteor的內置HTTP.post向Google OAuth2 API發送授權碼以獲取令牌。Google OAuth2的Meteor HTTP.post - 缺少必需的參數:grant_type

但是我收到錯誤:Required parameter is missing: grant_type。猜測這是一個編碼問題?

HTTP.post('https://accounts.google.com/o/oauth2/token', {data: { 
    code: 'XXXXXXXXXXX', 
    client_id : 'XXXXXXX.apps.googleusercontent.com', 
    client_secret: 'XXXXXXXXXXXXXXXXXXXXXXX', 
    grant_type : 'authorization_code' 
}}, function(error, response){ 
    if (error) { 
     console.log(error); 
    } else { 
     console.log(response); 

    } 
}); 

回答

0

我最終不得不將'data'換成'params',它包含它作爲POST請求的主體。

HTTP.post('https://accounts.google.com/o/oauth2/token', {params: { 
    code: 'XXXXXXXXXXX', 
    client_id : 'XXXXXXX.apps.googleusercontent.com', 
    client_secret: 'XXXXXXXXXXXXXXXXXXXXXXX', 
    grant_type : 'authorization_code' 
}}, function(error, response){ 
    if (error) { 
     console.log(error); 
    } else { 
     console.log(response); 
    } 
}); 
相關問題