【发布时间】:2017-06-28 17:44:10
【问题描述】:
我正在尝试返回 youtube API 的访问令牌,但不知道如何在 JQuery 中格式化此 POST
POST /oauth2/v4/token HTTP/1.1
Host: www.googleapis.com
Content-length: 184
content-type: application/x-www-form-urlencoded
user-agent: google-oauth-playground
client_secret=************&grant_type=refresh_token&refresh_token=1%2FPHiWsKPQXQJCNKBbTPgiR0QHugKlXp8Pd2cRlohjK80hAConmTyV5XVmg2HfO4Ag&client_id=407408718192.apps.googleusercontent.com
感谢您的帮助!
编辑:这是我目前的代码
jQuery.ajax({
url: "https://www.googleapis.com/oauth2/v4/token/",
type: "post",
data: {
grant_type: "refresh_token",
refresh_token: 'token here',
client_id: 'id here',
client_secret: 'secret here',
access_type: 'offline',
},
success: function(response){
console.log(response)
}
})
};
【问题讨论】:
-
stackoverflow.com/questions/5771878/… + api.jquery.com/jquery.post 应该足以供您用作参考。您是否有任何当前尝试的代码要显示在这里?
-
@G0dsquad 添加了我的代码编辑,感谢您的回复
-
您需要发布参数,而不仅仅是在 http get 请求的末尾添加它们。
标签: javascript jquery youtube-api http-post