2017-08-30 94 views
-1

我試圖從API獲取一些簡單的搜索字詞使用API​​ GET,但我不斷收到錯誤。任何人都可以在這裏看到我可能會出錯的地方嗎?Twitter API獲取錯誤

是我得到看起來像這樣的錯誤:

的jquery.js:5620爬不起來 https://api.twitter.com/1.1/search/tweets.json?q=bowery&callback=jQuery190024276804403583108_1504110377251&_=1504110377252

感謝, 丹尼。

$(document).ready(function() { 
 
    console.log('doc ready!'); 
 

 
    $('#submit').click(function() { 
 

 
    var search_term = { 
 
     q: 'bowery' 
 
    }; 
 
    console.dir(search_term); 
 
    search(search_term); 
 
    }); 
 

 
}); 
 

 
function search(search_term) { 
 
    console.log('searching for '); 
 
    console.dir(search_term); 
 

 
    $.ajax({ 
 
    url: 'https://api.twitter.com/1.1/search/tweets.json?' + $.param(search_term), 
 
    dataType: 'jsonp', 
 
    success: function(data) { 
 
     console.dir(data); 
 
    } 
 
    }) 
 

 
}
<!doctype html> 
 
<html> 
 

 
<head> 
 
    <title>Untitled Document</title> 
 
    <script src="http://code.jquery.com/jquery-1.9.0.min.js"></script> 
 

 
</head> 
 

 
<body> 
 
    <h1>NEW TWEETS</h1> 
 
    <ol id="tweets"> 
 
    </ol> 
 
    <a href="#" id="submit">get tweets</a> 
 
</body> 
 

 
</html>

+0

您需要使用您的api密鑰進行身份驗證 –

+0

只需將該網址粘貼到瀏覽器中。它說{「錯誤」:[{「code」:32,「message」:「無法驗證你。」}}}。 – Amit

+0

你如何驗證 – dannybots111

回答

1

你需要自己進行驗證。 Twitter API文檔有關於如何這樣做的文檔here

在你的情況下,你會有一些麻煩安全地進行身份驗證。由於您正在運行面向瀏覽器的代碼,因此檢查代碼的任何用戶都將能夠查看您的憑據並將其用於自己。

我建議查找一些關於如何根據您的需要使用Twitter API的示例。它不會像單個HTTP請求那麼簡單,並且很可能會要求您運行某種應用程序服務器。