* 4) Visit this page using your web browser.
 *
 * @author themattharris
 */
require '../tmhOAuth.php';
require '../tmhUtilities.php';
$tmhOAuth = new tmhOAuth(array('consumer_key' => 'YOUR_CONSUMER_KEY', 'consumer_secret' => 'YOUR_CONSUMER_SECRET', 'user_token' => 'A_USER_TOKEN', 'user_secret' => 'A_USER_SECRET'));
// we're using a hardcoded image path here. You can easily replace this with
// an uploaded image - see images.php in the examples folder for how to do this
// 'image = "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}",
// this is the image to upload. It should be in the same directory as this file.
$image = 'image.png';
$mime = 'image/png';
$delegator = 'http://posterous.com/api2/upload.json';
$x_auth_service_provider = 'https://api.twitter.com/1/account/verify_credentials.json';
generate_verify_header($tmhOAuth, $x_auth_service_provider);
$params = prepare_request($tmhOAuth, $x_auth_service_provider, $image, $mime);
// post to OAuth Echo provider
$code = make_request($tmhOAuth, $delegator, $params, false, true);
if ($code != 200) {
    tmhUtilities::pr('There was an error communicating with the delegator.');
    tmhUtilities::pr($tmhOAuth);
    die;
}
$resp = json_decode($tmhOAuth->response['response']);
$params = array('status' => 'I just OAuth echoed a picture: ' . $resp->url);
$code = make_request($tmhOAuth, $tmhOAuth->url('1/statuses/update'), $params, true, false);
if ($code == 200) {
    tmhUtilities::pr('Picture OAuth Echo\'d!');
    tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
} else {
Esempio n. 2
0
    return $params;
}
function make_request($tmhOAuth, $url, $params, $auth, $multipart)
{
    // make the request, no auth, multipart, custom headers
    $tmhOAuth->request('POST', $url, $params, $auth, $multipart);
    // Posterous liked it or not?
    if ($tmhOAuth->response['code'] == 200) {
        return json_decode($tmhOAuth->response['response']);
    }
    return false;
}
if (!empty($_FILES)) {
    // IMPORTANT: Posterous requires the host be https://api.twitter.com
    // versions 0.11+ of tmhOAuth default to SSL so do not need changing
    generate_verify_header($tmhOAuth);
    $params = prepare_request($tmhOAuth);
    // post to OAuth Echo provider
    $resp = make_request($tmhOAuth, 'http://posterous.com/api2/upload.json', $params, false, true);
    // post Tweet to Twitter
    if ($resp !== false) {
        $params = array('status' => 'I just OAuth echoed a picture: ' . $resp->url);
        $resp = make_request($tmhOAuth, $tmhOAuth->url('1/statuses/update'), $params, true, false);
        if ($resp) {
            $tmhOAuth->pr(json_decode($tmhOAuth->response['response']));
        } else {
            echo 'Error: ' . htmlentities($tmhOAuth->response['response']);
        }
    }
}
?>