Created
August 3, 2012 19:28
-
-
Save jzazove/3250690 to your computer and use it in GitHub Desktop.
Tip or Skip OAuth PHP Snippet
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
<?php | |
require 'OAuth.php'; | |
$key = '<your_app_key>'; | |
$secret = '<your_app_secret>'; | |
$consumer = new OAuthConsumer($key, $secret); | |
$sig_method = new OAuthSignatureMethod_HMAC_SHA1; | |
$my_domain = 'http://www.mydomain.net'; | |
$callback_url = '/some_callback_url'; | |
$api_endpoint_domain = 'https://tips.by'; | |
$api_endpoint = $api_endpoint_domain . '/oauth/request_token'; | |
$api_endpoint_signin = $api_endpoint_domain . '/oauth/authorize?oauth_token='; | |
$parameters = array('oauth_callback'=>$callback_url); | |
$req = OAuthRequest::from_consumer_and_token($consumer, null, "GET", $api_endpoint, $parameters); | |
$sig_method = new OAuthSignatureMethod_HMAC_SHA1(); | |
$req->sign_request($sig_method, $consumer, null); | |
$a = $req->to_url(); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $a); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
$response = curl_exec($ch); | |
curl_close($ch); | |
$token = OAuthUtil::parse_parameters($response); | |
//$_SESSION['oauth_token'] = $token['oauth_token']; | |
//$_SESSION['oauth_token_secret'] = $token['oauth_token_secret']; | |
echo '<a href="'. $api_endpoint_signin . $token['oauth_token'] . '">login</a>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment