Twitter with OAuth Example.\\ see also http://www.soramimi.jp/twicpp/index.html

Dependencies:   mbed HTTPClient NTPClient_NetServices EthernetNetIf

Committer:
soramimi
Date:
Thu Nov 15 00:51:45 2012 +0000
Revision:
1:c3f74457cad4
Twitter API address changed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
soramimi0:7ddb56bfde0c 1/*
soramimi0:7ddb56bfde0c 2 * OAuth http functions in POSIX-C.
soramimi0:7ddb56bfde0c 3 *
soramimi0:7ddb56bfde0c 4 * Copyright 2007, 2008, 2009, 2010 Robin Gareus <robin@gareus.org>
soramimi0:7ddb56bfde0c 5 *
soramimi0:7ddb56bfde0c 6 * Permission is hereby granted, free of charge, to any person obtaining a copy
soramimi0:7ddb56bfde0c 7 * of this software and associated documentation files (the "Software"), to deal
soramimi0:7ddb56bfde0c 8 * in the Software without restriction, including without limitation the rights
soramimi0:7ddb56bfde0c 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
soramimi0:7ddb56bfde0c 10 * copies of the Software, and to permit persons to whom the Software is
soramimi0:7ddb56bfde0c 11 * furnished to do so, subject to the following conditions:
soramimi0:7ddb56bfde0c 12 *
soramimi0:7ddb56bfde0c 13 * The above copyright notice and this permission notice shall be included in
soramimi0:7ddb56bfde0c 14 * all copies or substantial portions of the Software.
soramimi0:7ddb56bfde0c 15 *
soramimi0:7ddb56bfde0c 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
soramimi0:7ddb56bfde0c 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
soramimi0:7ddb56bfde0c 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
soramimi0:7ddb56bfde0c 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
soramimi0:7ddb56bfde0c 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
soramimi0:7ddb56bfde0c 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
soramimi0:7ddb56bfde0c 22 * THE SOFTWARE.
soramimi0:7ddb56bfde0c 23 *
soramimi0:7ddb56bfde0c 24 */
soramimi0:7ddb56bfde0c 25#if HAVE_CONFIG_H
soramimi0:7ddb56bfde0c 26# include <config.h>
soramimi0:7ddb56bfde0c 27#endif
soramimi0:7ddb56bfde0c 28
soramimi0:7ddb56bfde0c 29#include <stdio.h>
soramimi0:7ddb56bfde0c 30#include <stdarg.h>
soramimi0:7ddb56bfde0c 31#include <stdlib.h>
soramimi0:7ddb56bfde0c 32#include <string.h>
soramimi0:7ddb56bfde0c 33
soramimi0:7ddb56bfde0c 34#include "oauth.h"
soramimi0:7ddb56bfde0c 35
soramimi0:7ddb56bfde0c 36#include <HTTPClient.h>
soramimi0:7ddb56bfde0c 37
soramimi0:7ddb56bfde0c 38/* wrapper functions */
soramimi0:7ddb56bfde0c 39
soramimi0:7ddb56bfde0c 40/**
soramimi0:7ddb56bfde0c 41 * do a HTTP POST request, wait for it to finish
soramimi0:7ddb56bfde0c 42 * and return the content of the reply.
soramimi0:7ddb56bfde0c 43 * (requires libcurl or a command-line HTTP client)
soramimi0:7ddb56bfde0c 44 *
soramimi0:7ddb56bfde0c 45 * more documentation in oauth.h
soramimi0:7ddb56bfde0c 46 *
soramimi0:7ddb56bfde0c 47 * @param u url to query
soramimi0:7ddb56bfde0c 48 * @param p postargs to send along with the HTTP request.
soramimi0:7ddb56bfde0c 49 * @return In case of an error NULL is returned; otherwise a pointer to the
soramimi0:7ddb56bfde0c 50 * replied content from HTTP server. latter needs to be freed by caller.
soramimi0:7ddb56bfde0c 51 */
soramimi0:7ddb56bfde0c 52std::string oauth_http_post(const char *u, const char *p)
soramimi0:7ddb56bfde0c 53{
soramimi0:7ddb56bfde0c 54 HTTPClient http;
soramimi0:7ddb56bfde0c 55 HTTPText req("application/x-www-form-urlencoded");
soramimi0:7ddb56bfde0c 56 HTTPText res;
soramimi0:7ddb56bfde0c 57 req.set(p);
soramimi0:7ddb56bfde0c 58 http.post(u, req, &res);
soramimi0:7ddb56bfde0c 59 return res.get();
soramimi0:7ddb56bfde0c 60}
soramimi0:7ddb56bfde0c 61