2

I'm trying to write a program in C which will take each tweet from the streaming API and store it in a database. However, I can't get it to work, I'm using the below code:

#include <stdio.h>
#include <curl/curl.h>  
#include <stdlib.h>


size_t callback_func(void *ptr, size_t size, size_t count, void *stream) {
  /* ptr - your string variable.
  stream - data chuck you received */
printf("res %s \n \n", (char*)ptr); //prints chunck of data for each call.

}

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
   curl_easy_setopt(curl, CURLOPT_URL, "http://google.com/");
    //curl_easy_setopt(curl, CURLOPT_USERPWD, "JEggers2:password");
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, callback_func);
    curl_easy_perform(curl);

    /* always cleanup */ 
     curl_easy_cleanup(curl);


  }


  return 0;
}

This code only outputs one tweet in JSON format. What am I doing wrong? thanks

Adam Crossland
  • 14,198
  • 3
  • 44
  • 54
  • possible duplicate of [Accessing the Twitter Streaming API with C. ](http://stackoverflow.com/questions/4738002/accessing-the-twitter-streaming-api-with-c) – nmichaels Jan 20 '11 at 21:23

1 Answers1

1

The problem is that callback_func does not return anything.

According to the spec, you should return size if the read was successful.

Function pointer that should match the following prototype: size_t function( void *ptr, size_t size, size_t nmemb, void *userdata); This function gets called by libcurl as soon as there is data received that needs to be saved. The size of the data pointed to by ptr is size multiplied with nmemb, it will not be zero terminated. Return the number of bytes actually taken care of. If that amount differs from the amount passed to your function, it'll signal an error to the library. This will abort the transfer and return CURLE_WRITE_ERROR.