Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
TwitterAPI的JSON HTTP请求示例?_Json_Twitter - Fatal编程技术网

TwitterAPI的JSON HTTP请求示例?

TwitterAPI的JSON HTTP请求示例?,json,twitter,Json,Twitter,我想向twitter api发出请求。这是文档中提供的示例(https://dev.twitter.com/docs/api/1/get/search): 文档中没有示例请求。对该url的请求如何包括带有数据响应的警报?如果这有帮助,我为您举了一个例子: 基本上,HTML代码包含2个输入。一个用于按钮,一个用于查询字符串 <html> <head> <title>example</title> </head> <body&

我想向twitter api发出请求。这是文档中提供的示例(https://dev.twitter.com/docs/api/1/get/search):


文档中没有示例请求。对该url的请求如何包括带有数据响应的警报?

如果这有帮助,我为您举了一个例子:

基本上,HTML代码包含2个输入。一个用于按钮,一个用于查询字符串

<html>
<head>
    <title>example</title>
</head>
<body>
   <div style="padding: 20px;">
        <input id="query" type="text" value="blue angels" />
        <input id="submit" type="button" value="Search" />
    </div>
    <div id="tweets" style="padding: 20px;">
        Tweets will go here.
    </div>
</body>
</html>

例子
推特将在这里发布。
按下搜索按钮后,您将向twitter发送一个请求,请求包含查询字符串的5个结果(rpp)

<html>
<head>
    <title>example</title>
</head>
<body>
   <div style="padding: 20px;">
        <input id="query" type="text" value="blue angels" />
        <input id="submit" type="button" value="Search" />
    </div>
    <div id="tweets" style="padding: 20px;">
        Tweets will go here.
    </div>
</body>
</html>
以下是此页面的javascript:

function searchTwitter(query) {
    $.ajax({
        url: 'http://search.twitter.com/search.json?' + jQuery.param(query),
        dataType: 'jsonp',
        success: function(data) {
            var tweets = $('#tweets');
            tweets.html('');
            for (res in data['results']) {
                tweets.append('<div>' + data['results'][res]['from_user'] + ' wrote: <p>' + data['results'][res]['text'] + '</p></div><br />');
        }
        }
    });
}

$(document).ready(function() {
    $('#submit').click(function() {
        var params = {
            q: $('#query').val(),
            rpp: 5
        };
        // alert(jQuery.param(params));
        searchTwitter(params);
    });
});
函数搜索Twitter(查询){
$.ajax({
网址:'http://search.twitter.com/search.json?'+jQuery.param(查询),
数据类型:“jsonp”,
成功:功能(数据){
var tweets=$(“#tweets”);
html(“”);
对于(数据中的res['results']){
追加(“”+data['results'][res]['from_user']+'写:'+data['results'][res]['text']+'


'); } } }); } $(文档).ready(函数(){ $(“#提交”)。单击(函数(){ 变量参数={ q:$('#query').val(), rpp:5 }; //警报(jQuery.param(params)); 搜索推特(params); }); });
诀窍在于jQuery.param()函数,您将为搜索/请求传递参数

看到它在这里运行:


自从Twitter发布API 1.1以来,这已经不起作用了。看看这个问题,学习如何使用API 1.1:

我没有得到您真正需要的。你错过了什么?这是一个JSON编码的对象。你只需要知道整个结构。这里有一个更“可见”的响应信息:我不知道如何处理请求。我尝试了简单的ajax,但没有成功。我并不是说我做得对,相反,我肯定我做得不对,所以我只想举一个json对象请求的例子来了解它是如何完成的。您是否使用javascript/jquery?php?我正在使用jquery和php。我正在尝试使用js和jquery来执行请求。