Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active March 18, 2022 20:37
Show Gist options
  • Save danielpataki/c7e98b9596bfb6d085b0 to your computer and use it in GitHub Desktop.
Save danielpataki/c7e98b9596bfb6d085b0 to your computer and use it in GitHub Desktop.
HTTP API
$token = get_transient( 'twitter_access_token' );
$token = ( empty( $token ) ) ? get_twitter_access_token() : $token;
$request = wp_remote_get('https://api.twitter.com/1.1/followers/ids.json?screen_name=danielpataki&count=5', array(
'headers' => array(
'Authorization' => 'Bearer ' . $token,
'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8'
),
'httpversion' => '1.1'
));
$token = json_decode( $request['body'] );
$request = wp_remote_get( 'https://api.pinterest.com/v1/boards/marticz/home-office/pins/?access_token=<your access token>' );
$pins = json_decode( $request['body'], true );
if( !empty( $pins['data'] ) ) {
echo '<ul>';
foreach( $pins['data'] as $pin ) {
echo '<li><a href="' . $pin['url'] . '">' . $pin['note']. '</a></li>';
}
echo '</ul>';
}
$test = wp_remote_get( 'http://google.com' );
echo "<pre>";
var_dump($test);
echo "</pre>";
$key = base64_encode( urlencode( "n8KP16uvGZA6xvFTtb8IAA:i4pmOV0duXJv7TyF5IvyFdh5wDIqfJOovKjs92ei878" ) );
$request = wp_remote_post('https://api.twitter.com/oauth2/token', array(
'headers' => array(
'Authorization' => 'Basic ' . $key,
'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8'
),
'body' => 'grant_type=client_credentials',
'httpversion' => '1.1'
));
$token = json_decode( $request['body'] );
echo "<pre>"; var_dump($token); echo "</pre>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment