Last active
March 18, 2022 20:37
-
-
Save danielpataki/c7e98b9596bfb6d085b0 to your computer and use it in GitHub Desktop.
HTTP API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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'] ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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>'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$test = wp_remote_get( 'http://google.com' ); | |
echo "<pre>"; | |
var_dump($test); | |
echo "</pre>"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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