Ejemplo n.º 1
0
public function oauth_request($url, $method='POST', $user_access_key, $user_access_secret, $data) {

	$tmhOAuth = new tmhOAuth(array(
		'consumer_key' => $this->consumer_key,
		'consumer_secret' => $this->consumer_secret,
		'user_token' => $user_access_key,
		'user_secret' => $user_access_secret,
	));

	$code = $tmhOAuth->request($method, $tmhOAuth->url($url), $data);

	if ($code == 200) {
		tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
	} else {
		tmhUtilities::pr($tmhOAuth->response['response']);
	}

}
Ejemplo n.º 2
0
// 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 {
    tmhUtilities::pr('There was an error from Twitter.');
    tmhUtilities::pr($tmhOAuth);
    die;
}
function generate_verify_header($tmhOAuth, $x_auth_service_provider)
{
    // generate the verify crendentials header -- BUT DON'T SEND
    // we prevent the request because we're not the ones sending the verify_credentials request, the delegator is
    $tmhOAuth->config['prevent_request'] = true;
    $tmhOAuth->request('GET', $x_auth_service_provider);
    $tmhOAuth->config['prevent_request'] = false;
}
function prepare_request($tmhOAuth, $x_auth_service_provider, $media, $media_type = 'image/jpeg')
{
    // create the headers for the echo
    $headers = array('X-Auth-Service-Provider' => $x_auth_service_provider, 'X-Verify-Credentials-Authorization' => $tmhOAuth->auth_header);
    // load the headers for the request
Ejemplo n.º 3
0
 * This example is intended to be run from the command line.
 *
 * Instructions:
 * 1) If you don't have one already, create a Twitter application on
 *      https://dev.twitter.com/apps
 * 2) From the application details page copy the consumer key and consumer
 *      secret into the place in this code marked with (YOUR_CONSUMER_KEY
 *      and YOUR_CONSUMER_SECRET)
 * 3) From the application details page copy the access token and access token
 *      secret into the place in this code marked with (A_USER_TOKEN
 *      and A_USER_SECRET)
 * 4) Update $image to point to a real image file on your computer.
 * 5) In a terminal or server type:
 *      php /path/to/here/photo_tweet.php
 *
 * @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 jpeg file to upload. It should be in the same directory as this file.
$image = 'image.jpg';
$code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json', array('media[]' => "@{$image};type=image/jpeg;filename={$image}", 'status' => 'Picture time'), true, true);
if ($code == 200) {
    tmhUtilities::pr(json_decode($tmhOAuth->response['response']));
} else {
    tmhUtilities::pr($tmhOAuth->response['response']);
}
Ejemplo n.º 4
0
/**
 * Verify the user token and secret works. If successful we will be given the
 * details of the user. If not an error explaining why will be returned.
 *
 * Although this example uses your user token/secret, you can use
 * the user token/secret of any user who has authorised your application.
 *
 * Instructions:
 * 1) If you don't have one already, create a Twitter application on
 *      https://dev.twitter.com/apps
 * 2) From the application details page copy the consumer key and consumer
 *      secret into the place in this code marked with (YOUR_CONSUMER_KEY
 *      and YOUR_CONSUMER_SECRET)
 * 3) From the application details page copy the access token and access token
 *      secret into the place in this code marked with (A_USER_TOKEN
 *      and A_USER_SECRET)
 * 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'));
$code = $tmhOAuth->request('GET', $tmhOAuth->url('1/account/verify_credentials'));
if ($code == 200) {
    echo 'The access level of this token is: ' . $tmhOAuth->response['headers']['x_access_level'] . PHP_EOL;
    tmhUtilities::pr($tmhOAuth->response);
} else {
    tmhUtilities::pr(htmlentities($tmhOAuth->response['response']));
}
Ejemplo n.º 5
0
function outputError($tmhOAuth)
{
    echo 'Error: ' . $tmhOAuth->response['response'] . PHP_EOL;
    tmhUtilities::pr($tmhOAuth);
}
Ejemplo n.º 6
0
        echo $tweet['id_str'];
        ?>
</span><br>
    <span>Orig: <?php 
        echo $tweet['text'];
        ?>
</span><br>
    <span>Entitied: <?php 
        echo $entified_tweet;
        ?>
</span><br>
    <small><?php 
        echo $permalink;
        if ($is_retweet) {
            ?>
is retweet<?php 
        }
        ?>
    <span>via <?php 
        echo $tweet['source'];
        ?>
</span></small>
  </div>
<?php 
    }
} else {
    tmhUtilities::pr($tmhOAuth->response);
}
?>
</body>
</html>
Ejemplo n.º 7
0
 public function twitter_upload()
 {
     $this->autoRender = false;
     App::import('Vendor', 'tmhOAuth-master/tmhOAuth');
     App::import('Vendor', 'tmhOAuth-master/tmhUtilities');
     $token = $_COOKIE['Temp_Token'];
     $secret = $_COOKIE['Temp_Secret'];
     $Img_name = $_COOKIE['Img_name'];
     $img = $_COOKIE['Img_Url'];
     $redirect_Url = $_COOKIE['redirect_Url'];
     $price = $_COOKIE['price'];
     $pageLink = $_COOKIE['pageLink'];
     $name = basename($img);
     $txt = $Img_name . ' $' . $price . ' link:' . $pageLink;
     $tmhOAuth = new tmhOAuth(array('consumer_key' => 'wFSwIc9Mx5XJjDbAJN7iNHmGo', 'consumer_secret' => '0XcpY5qXZyOy6MU7AQ34Cj72aYVdp9uV2cg4tunbl6GqrUzMtQ', 'user_token' => $token, 'user_secret' => $secret, 'curl_ssl_verifypeer' => false));
     $tmhOAuth->request("POST", $tmhOAuth->url("oauth/access_token", ""), array('oauth_verifier' => $_GET["oauth_verifier"]));
     $response = $tmhOAuth->extract_params($tmhOAuth->response["response"]);
     $tmhOAuth->config["user_token"] = $response['oauth_token'];
     $tmhOAuth->config["user_secret"] = $response['oauth_token_secret'];
     $code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json', array('media[]' => file_get_contents($img), 'status' => "{$txt}"), true, true);
     if ($code == 200) {
         $this->Session->setFlash('Your image tweet has been sent successfully', 'default', array('class' => 'alert alert-success'));
         $this->redirect($redirect_Url);
         die;
     } else {
         tmhUtilities::pr($tmhOAuth->response['response']);
     }
 }
Ejemplo n.º 8
0
        // Call
        $authurl = $app['tmhOAuth']->url("oauth/authorize", '') . "?oauth_token={$oauth['oauth_token']}";
        return $app->redirect($authurl);
    } else {
        tmhUtilities::pr(htmlentities($app['tmhOAuth']->response['response']));
    }
});
// Change the avatar
$app->post('/change', function () use($app) {
    // Catch access token from session
    $accessToken = $app['session']->get('access_token');
    $app['tmhOAuth']->config['user_token'] = $accessToken['oauth_token'];
    $app['tmhOAuth']->config['user_secret'] = $accessToken['oauth_token_secret'];
    // Fake upload - assume the perfect avatar
    $_FILES['image']['tmp_name'] = __DIR__ . '/../web/img/avatar.png';
    $_FILES['image']['type'] = 'image/png';
    $_FILES['image']['name'] = 'avatar.png';
    $params = array('image' => "@{$_FILES['image']['tmp_name']};type={$_FILES['image']['type']};filename={$_FILES['image']['name']}");
    // Update the user's avatar
    $code = $app['tmhOAuth']->request('POST', $app['tmhOAuth']->url("1/account/update_profile_image"), $params, true, true);
    // If everything's good, go to congrats page
    if ($code == 200) {
        return $app->redirect('/congratulations');
    }
    tmhUtilities::pr(htmlentities($app['tmhOAuth']->response['response']));
});
// Congrats!
$app->get('/congratulations', function () use($app) {
    return $app['twig']->render('_congrats.html.twig');
});
return $app;
Ejemplo n.º 9
0
//$connection->post('friendships/create', array('id' => 9436992));
//$connection->post('friendships/destroy', array('id' => 9436992));
/* statuses/update */
//$image = "./button001.jpg";
$image = "c:\\wamp\\www\\Valspar\\Assets\\01_Tab\\House_" . $_GET['ID'] . ".png";
//$filepath = "button001.jpg"; $filetype = "image/jpeg"; $fileName = "button0001.jpg";
//$image = "{$filepath};type={$filetype};filename={$fileName}";
date_default_timezone_set('GMT');
//$parameters = array('status' => "Why I can't share", 'media[]' => "@$image;type=image/jpeg;filename=$image" );
//$parameters = array('status' => "Why I can't share", 'media[]' => "@{$image};type=image/jpeg;filename={$image}" );
//$status = $connection->post('statuses/update_with_media', $parameters);
//$code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json',
$code = $connection->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json', array('media[]' => "@{$image};type=image/png;filename={$image}", 'status' => $_GET['String']), true, true);
if ($code == 200) {
    /* Create a TwitterOauth object with consumer/user tokens. */
    $Getter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
    /* If method is set change API call made. Test is called by default. */
    $content = $Getter->get('account/verify_credentials');
    $_SESSION['SubmitID'] = $_GET['SubmitID'];
    $_SESSION['PictureSelect'] = $_GET['ID'];
    require "../SQL.php";
    //	var_dump($content->id_str);
    //	var_dump($content->name);
    //  tmhUtilities::pr(json_decode($connection->response['response']));
    //	header( 'Location: '.json_decode($connection->response['response'])->entities->media[0]->expanded_url );
    echo json_decode($connection->response['response'])->entities->media[0]->expanded_url;
    //	var_dump( json_decode($connection->response['response'])->entities );
} else {
    var_dump($connection);
    tmhUtilities::pr($connection->response['response']);
}