I am trying to return an access token for the youtube API but do not know how to format this POST in JQuery
POST /oauth2/v4/token HTTP/1.1
Host: www.googleapis
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
Thanks for any help!
EDIT: This is my code so far
jQuery.ajax({
url: "/",
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)
}
})
};
I am trying to return an access token for the youtube API but do not know how to format this POST in JQuery
POST /oauth2/v4/token HTTP/1.1
Host: www.googleapis.
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.
Thanks for any help!
EDIT: This is my code so far
jQuery.ajax({
url: "https://www.googleapis./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)
}
})
};
Share
Improve this question
edited Feb 10, 2017 at 12:34
Peter Maher
asked Feb 10, 2017 at 11:29
Peter MaherPeter Maher
991 silver badge11 bronze badges
3
- 2 stackoverflow./questions/5771878/… + api.jquery./jquery.post should be enough for you to use as a reference. Have you any current attempted code to show on here? – G0dsquad Commented Feb 10, 2017 at 11:31
- @G0dsquad added edit of my code so far, thanks for reply – Peter Maher Commented Feb 10, 2017 at 11:41
- you need to post the parameters not just tack them on the end of the request that's for http get. – Linda Lawton - DaImTo Commented Feb 10, 2017 at 12:25
2 Answers
Reset to default 4You can use AJAX for that. In my opinion .ajax()
is the best method but you can even use the .post()
method.
Using .ajax()
$.ajax({
method: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
Using .post()
$.post( "test.php", { 'choices[]': [ "Jon", "Susan" ] } );
For both cases you have to set your user-agent with this (see .ajaxSetup()
):
$.ajaxSetup({
beforeSend: function(request) {
request.setRequestHeader("User-Agent","google-oauth-playground");
}
});
I guess you are missing a ?
/v4/token?client_secret=*******
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745363223a4624454.html
评论列表(0条)