codingbadger / instant-tokens.com

11 stars 0 forks source link

Jquery ajax request doesnt work to provided URL #30

Closed kr1stjans closed 2 years ago

kr1stjans commented 2 years ago

Jquery ajax request doesnt work to provided URL. I get the following error:

Access to XMLHttpRequest at 'https://ig.instant-tokens.com/users/user-id/instagram/some-other-idtoken?userSecret=token' from origin 'https://mydomain.si' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. jquery-2.2.3.min.js:4 GET https://ig.instant-tokens.com/users/user-id/instagram/some-other-idtoken?userSecret=tokennet::ERR_FAILED

I am using instnat-tokens with instafeed like so:

var feed = new Instafeed({
                                template: '<a class="ig-post" href="{{link}}">' +
                                    '<div><b>{{username}}</b>{{caption}}</div>' +
                                    '<img title="{{caption}}" src="{{image}}"></a>',
                                accessToken: function (done) {
                                    $.ajax({
                                        url: 'https://ig.instant-tokens.com/users/<user-id>/instagram/<some-other-id>token?userSecret=<token>',
                                        dataType: 'json'
                                    }).done(function (response) {
                                        if (response.Token) {
                                            done(null, response.Token);
                                        } else {
                                            done(new Error('error: ' + response));
                                        }
                                    });
                                }
                            });
                            feed.run();
codingbadger commented 2 years ago

There are no restrictions on the API with regards to origin. No other users are reporting an issue so this would point to an issue with your code I am afraid.

kr1stjans commented 2 years ago

Thanks. If anyone else has a problem, we had a global ajax config which the API refused:


$.ajaxSetup({
        xhrFields: {
            withCredentials: true
        }, headers : {
            'X-some-id-session-id' : 'id'
        }
    });