405 - Method Not Allowed


#1

Our client uses SharePoint Online. They want to be able to see latest 2 tweets according to the “@SomeTweets” tag. So, what we tried to do:

  1. Created CustomAccount
  2. Create Application CustomAccountApplication
  3. We generated bearer credentials using consumerKey and consumerSecret
  4. We added next script to the page in SharePoint

    function GetTwitter() {
    $.ajax({
    type: “POST”,
    url: “https://api.twitter.com/oauth2/token”,
    beforeSend: SetHeaders,
    success: function (msg) {
    alert(msg);
    },
    error: function (xhr) {
    alert("An error occured : " + xhr.status + " " + xhr.statusText);
    },
    dataType: “json”,
    data: { grant_type: “client_credentials” }
    });
    }
    function SetHeaders(xhr) {
    xhr.setRequestHeader(“Authorization”, “Basic SomeBearerCredentials”);
    xhr.setRequestHeader(“Content-Type”, “application/x-www-form-urlencoded;charset=UTF-8”);
    }

    However, it doesn’t work and we are getting next error “405 - Method Not Allowed” (see the results from Network capturing). What am I doing wrong? Or maybe there is another way to achieve the requirements of the client.

version - 1.1
browser - Internet Explorer - 10.0.9200.16798
request:
method - OPTIONS
url - https://api.twitter.com/oauth2/token
httpVersion - HTTP/1.1

headers:
Accept - /
Origin - http://localhost:27217
Access-Control-Request-Method - POST
Access-Control-Request-Headers - content-type, accept, authorization
Accept-Encoding - gzip, deflate
User-Agent - Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0)
Host - api.twitter.com
Content-Length - 0
Connection - Keep-Alive
Cache-Control - no-cache

response:
status - 405
statusText - Method Not Allowed
httpVersion - HTTP/1.1


#2

Have you managed to fix this issue? I am facing the same problem :frowning: