Hi there,
I am trying to use ajax to change the title of a stream but I keep getting the 500 error:
Object {error: “Internal Server Error”, status: 500, message: null}
here is the code, I have tried so many variations on it - anyone got any idea what’s wrong? Is this the correct way to do it? I used this from here: Twitch Api - Changing channel status fail via jQuery Ajax put method - Stack Overflow
function changeTitle() { //Changing stream title
titleStr = "test title"
token = userLoggedIn
$.ajax({
url: 'https://api.twitch.tv/kraken/channels/mychannel?channel[status]='+titleStr+'&oauth_token=' +token+'&_method=put',
type: 'PUT',
contentType: 'application/json',
dataType: 'jsonp',
success: function(data) {
console.log(data.status);
console.log(data)
}
});
}
george
January 22, 2015, 10:08pm
2
AidanDaniel97:
type: ‘PUT’,
I don’t think that will work with JSONP. You might have to add _method=PUT
as a query string param instead.
BTM_pl
January 23, 2015, 7:15am
3
Have you tried authenticating by passing the oauth token as a header, not query param, as stated in the documentation ?
curl -H 'Accept: application/vnd.twitchtv.v2+json' -H 'Authorization: OAuth <access_token>' -d "channel[status]=Playing+cool+new+game!&channel[game]=Diablo" -X PUT https://api.twitch.tv/kraken/channels/test_user1
You can use headers{} field in jQuery to send custom headers.
BTM_pl
January 23, 2015, 7:17am
4
He already did add it in the query string, might want to change type: PUT
to type: GET
though.
I have tried GET and PUT and it doesn’t work still for some reason … could you give an example of using the headers? Thanks
BTM_pl
January 23, 2015, 6:53pm
6
Try
$.ajax({
url: 'https://api.twitch.tv/kraken/channels/mychannel?channel[status]='+titleStr+'&_method=put',
type: 'GET',
contentType: 'application/json',
dataType: 'jsonp',
headers: {
'Authorization': 'OAuth TOKEN_HERE' // the "OAuth " is important too!
},
success: function(data) {
console.log(data.status);
console.log(data)
}
});
Of course you ARE replacing “mychannel” with your channel name?
hmmm thanks but I tried that and it still doesn’t seem to be working? aha yea I have changed it to my channel to test (AidanDaniel97)
$.ajax({
url: 'https://api.twitch.tv/kraken/channels/aidandaniel97?channel[status]='+titleStr+'&_method=put',
type: 'GET',
contentType: 'application/json',
dataType: 'jsonp',
headers: {
'Authorization': token // the "OAuth " is important too!
},
success: function(data) {
console.log(data.status);
console.log(data)
}
});
then I get this error:
Object {error: “Unauthorized”, status: 401, message: “Token invalid or missing required scope”}
I have also found this:
Good day. Im trying to change my channel title by using this code: jsontext = JSON.stringify(['channel', {'status': 'MY TITLE'}]); $.ajax({ url: 'https://api.twitch.tv/kraken/channels/mychannel', type: 'PUT', headers:...
Reading time: 1 mins 🕑
Likes: 1 ❤
but that does not work at all, the code still gives the 500 error
BTM_pl
January 23, 2015, 8:01pm
8
Ok, I believe there must be something wrong with your access token then. I’ve just tested the following code and it works fine:
$.ajax({
url: 'https://api.twitch.tv/kraken/channels/btm_pl?channel[status]=TESTING_STUFF&_method=put&oauth_token=9c66pnqc474s87yx2cqjs7imbzrAAAA',
type: 'GET',
contentType: 'application/json',
dataType: 'jsonp',
success: function(data) {
console.log(data.status);
console.log(data)
}
});
Make sure you request the channel_editor
scope when asking for oauth token. Remember that asking for a different oauth token (with different scopes) further in the app flow will invalidate the previous token.
1 Like
BTM_pl:
btm_pl
Wooop woop!!! thanks a lot!
It seemed that I was actually being a huge huge noob and I was getting the token from the session storage but I wasn’t parsing it so I wasn’t actually getting the token I was just getting a huge string!!
Thanks a lot for your help !!!
system
Closed
February 2, 2015, 9:15pm
10
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.