我正在尝试使用 C 访问 Streaming API,并使用以下代码:
#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;
}
执行时不打印任何内容,我做错了什么?谢谢。EDIT:当我使用 google.com 作为 URL 时,该代码可以正常工作,但这似乎只是 Streaming API 的问题。有任何想法吗?
功能卷曲_easy_perform()仅返回错误代码。要实际检索数据,您必须设置CURLOPT_WRITEFUNCTION到你自己的回调函数。
编辑:您也不能在 URL 字符串中使用“-uJEggers2:password”,您必须使用以下命令设置身份验证选项CURLOPT_HTTPAUTH, CURLOPT_USERNAME and CURLOPT_PASSWORD.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)