What is the problem in the bellow code

restapi
rest
oauth

#1

I’m getting this error:

GET https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=hasnain313_khan&include_rts=false&count=3&include_entities=true 400 ()
send @ jquery-3.2.1.js:9566
ajax @ jquery-3.2.1.js:9173
(anonymous) @ main.js:7
mightThrow @ jquery-3.2.1.js:3583
process @ jquery-3.2.1.js:3651
index.html:1 XMLHttpRequest cannot load https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=hasnain313_khan&include_rts=false&count=3&include_entities=true. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘null’ is therefore not allowed access.

The response had HTTP status code 400.

This is the code:

$(document).ready(function(){

var $tweet = $('#tweets');
var $txt = $('#txt-area');

$.ajax({
type: ‘GET’,
url: ‘https://api.twitter.com/1.1/statuses/user_timeline.json’,
dataType: “json”,
header: { Authorization: “OAuth”, oauth_consumer_key: “consumer_key”, oauth_consumer_secret: “consumer_secret”, oauth_access_token: “access_token”, oauth_access_token_secret: “access_token_secret” },
data: {
screen_name: ‘hasnain313_khan’,
include_rts: false,
count: 3,
include_entities: true
},
success: function(data, text){
var html = ‘

  • TWEET
  • ’;
    $tweet.append(html.replace(‘TWEET’, tweets(data.text)));
    },
    error: function(){
    alert(“error loading”);
    }
    });

    $(’#tweeting’).on(‘click’,function(){

      var tweet = {
    
        tweet: $txt.val(),
      };
    
      $.ajax({
    
         type: 'POST',
         url: 'https://api.twitter.com/1.1/statuses/update.json',
         data: {
         consumer_key: 'consumer_key',
         consumer_secret: 'consumer_secret',
         access_token: 'access_token',
         access_token_secret: 'access_token_secret'
    
         },
         data: 'status',
         success: function(newData){
    
           $tweet.append('<li>tweet: '+ newData.tweet + ' </li>');
    
         },
          error: function(){
            alert('error tweeting')
          }
    
      });
    

    });

    });


    #2

    This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.