访问与C Twitter的流API [英] Accessing the Twitter Streaming API with C
问题描述
我试图访问与C流API,和我用下面的code:
I'm trying to access the Streaming API with C, and am using the following code:
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://stream.twitter.com/1/statuses/sample.json?delimited=length -uJEggers2:password");
res = curl_easy_perform(curl);
printf("results: %c", res);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
这没什么打印在执行时,我究竟做错了什么?谢谢。
修改的code工作时,我用google.com的网址,但它只是似乎是与流API的问题。有任何想法吗?
This prints nothing upon execution, what am I doing wrong? Thanks. The Code works when I use google.com as the URL, but it just seems to be an issue with the Streaming API. Any Ideas?
推荐答案
函数 curl_easy_perform( )只返回错误code。要实际检索数据,你必须设置 CURLOPT_WRITEFUNCTION 以自己回调函数。
The function curl_easy_perform() only returns the error code. To actually retrieve the data you'll have to set CURLOPT_WRITEFUNCTION to your own callback function.
编辑:您也不能使用-uJEggers2:密码中的URL字符串,你必须设置使用的 CURLOPT_HTTPAUTH , CURLOPT_USERNAME 和 CURLOPT_PASSWORD 。
You also can't use " -uJEggers2:password" in the URL string, you'll have to set the authentication options using CURLOPT_HTTPAUTH, CURLOPT_USERNAME and CURLOPT_PASSWORD.
这篇关于访问与C Twitter的流API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!