使用 C 访问 Twitter Streaming API [英] Accessing the Twitter Streaming API with C

查看:45
本文介绍了使用 C 访问 Twitter Streaming API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 C 访问流 API,并使用以下代码:

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;
}

这在执行时不打印任何内容,我做错了什么?谢谢.当我使用 google.com 作为 URL 时,代码有效,但它似乎是 Streaming 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() 只返回错误代码.要实际检索数据,您必须将 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.

您也不能在 URL 字符串中使用-uJEggers2:password",您必须使用 CURLOPT_HTTPAUTH, CURLOPT_USERNAMECURLOPT_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 Streaming API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆