Sorry I have looked over the GitHub pages, can I use the Twitch.api{} JS SDK to perform actions on the users / follows end point?
I don’t see a way of sending the post type of PUT and Delete in the GitHub docs.
Sorry I have looked over the GitHub pages, can I use the Twitch.api{} JS SDK to perform actions on the users / follows end point?
I don’t see a way of sending the post type of PUT and Delete in the GitHub docs.
You can add a verb to Twitch.api
to specify the PUT or DELETE:
Twitch.api({method: '/users/:user/follows/channels/:target', verb: 'PUT' }, function([...]) {
[...]
});
Alternatively if you’d like to make the calls manually, the API supports a _method
query string parameter:
https://api.twitch.tv/kraken/users/test_user1/follows/channels/test_channel?_method=PUT
So assuming I have a data attr set on the link and window object contains the logged in user and when I logged in I passed the flag: user_follows_edit
This should work:
$('body').on('click', '.twitch-follow', function () {
var twitch_target = $(this).attr("data-twitch-name");
var twitch_name = window.twitch_name;
var twitch_follow_url = "/users/" + twitch_name + "/follows/channels/" + twitch_target;
Twitch.api({
method: twitch_follow_url,
verb: "PUT"
},
function (error, channel) {
if (error) {
alert('error');
}
if (channel) {
alert('Sucess');
}
});
});
But I always get a SUCCESS response of the channel object. When I use PUT or DELETE.
Nothing happens and XHR shows a type of GET response.
Can some one do a quick test to ensure I am not going mental please
It turns out I am not going mental…
<script src="https://ttv-api.s3.amazonaws.com/twitch.min.js"></script>
This file listed on the GitHub tutorial doesn’t support the verb method. It works fine when I used a downloaded version of the file on GitHub.
If you are already using JQuery I highly recommend just doing your requests through that and ditching that old and, excuse my language, piece of garbage JS SDK.
Seriously. Just use the “_method” param instead.
LOL, Ok dude ty for the insight
The _method was how I noticed the issue with the amazon file missing this code.
Considering writing our own JS SDK if there is any one wanting to contribute?
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.