Access Twitter Streaming APIs Using C

I am trying to access the Streaming API using C and use 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;
}

It does not display anything at runtime, what am I doing wrong? Thank you EDIT: The code works when I use google.com as the URL, but this is just a problem with the Streaming API. Any ideas?

+3
source share
2 answers

The curl_easy_perform () function returns an error code. To really get the data, you will need to set CURLOPT_WRITEFUNCTION to your own callback function.

: "-uJEggers2: password" URL, , CURLOPT_HTTPAUTH, CURLOPT_USERNAME CURLOPT_PASSWORD.

+3

edit: , google.com API twitter , "-u user: pass". API CURL , .

curl_easy_setopt (curl, CURLOPT_USERPWD, "user: pass" ), " " http://curl.haxx.se/libcurl/c/curl_easy_setopt.html

0

Source: https://habr.com/ru/post/1786443/


All Articles