Beispiel #1
0
function get_auth_url()
{
    $retarr = get_request_token(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback, false, true, true);
    if (!empty($retarr)) {
        list($info, $headers, $body, $body_parsed) = $retarr;
        if ($info['http_code'] == 200 && !empty($body)) {
            echo "http://api.twitter.com/oauth/authorize?" . rfc3986_decode($body) . "\n";
        }
    }
}
Beispiel #2
0
<?php

require 'globals.php';
require 'oauth_helper.php';
// Callback can either be 'oob' or a url whose domain must match
// the domain that you entered when registering your application
$callback = 'oob';
// Get the request token using HTTP GET and HMAC-SHA1 signature
$retarr = get_request_token(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback, false, true, true);
if (!empty($retarr)) {
    list($info, $headers, $body, $body_parsed) = $retarr;
    if ($info['http_code'] == 200 && !empty($body)) {
        print "Have the user go to xoauth_request_auth_url to authorize your app\n" . rfc3986_decode($body_parsed['xoauth_request_auth_url']) . "\n";
    }
}
exit(0);
/**
 * Get a request token.
 * @param string $consumer_key obtained when you registered your app
 * @param string $consumer_secret obtained when you registered your app
 * @param string $callback callback url can be the string 'oob'
 * @param bool $usePost use HTTP POST instead of GET
 * @param bool $useHmacSha1Sig use HMAC-SHA1 signature
 * @param bool $passOAuthInHeader pass OAuth credentials in HTTP header
 * @return array of response parameters or empty array on error
 */
function get_request_token($consumer_key, $consumer_secret, $callback, $usePost = false, $useHmacSha1Sig = true, $passOAuthInHeader = false)
{
    $retarr = array();
    // return value
    $response = array();
<?php

require 'globals.php';
require 'oauth_helper.php';
// Fill in the next 3 variables.
$old_access_token = 'A=KdfjadlskfjSDFGG.ertklsioerkjhSDFGkjlhasdfik345k34897SDFgklhe4kljhdSGKLjhsdfg.mcxkhdfSGKHsdfgkjeroI.REsdFGSFDg.sdfgiwresdfgsfhg.gh.tyu.ghfj.dfghfsdg.fgsdg.sdfgiretkjsfdgkjlhertiuysdfgkjhsdfgkljertkjhsdfguyert8743508972345lkjhsdfi8g89sdfg89sdfg908sdfg897sdfg8sdfg734jk25kljhwdkjlhsdfgkjlhsfdgkjlhsdfgjkhsdfgkjhsfdgiuywert87425ksdkjhlsdfgkjlhsdfgjklcxbm.cxvb.asfdkljadsflk.jasldkj3452387wert98sdfg8sdfg897sdfg890sdfgpoiret.lsdfgkljsdfgiwret_sfgkjhmnsdfgjkcvbmsdfglkjhewrtiusdfgjkhsdfgiuret87245lkjhdsfg.mnvbkisdfwertrwt.42534wertwgsdfg.cxvbsfdgsdfg.rwetwert.452435wertwretwer.wertwergtsdfgsdfg.sdfgsdfgrewtwret4252345wtdfgsdfg.sdfgsdfgsdfgewrtwert23452345wertwgsdfgfdrtyfhdgsdfgsdfgrewtwertsdfgdfgrt2rwersdfgdfgretrwefgrwtwertwertweryrwywertwertfsgfsdgsdferw3452twresdfgwretwert45wrtertrtg-';
$old_token_secret = 'o2345w980945353478594867g3454l45lk324wrd';
$oauth_session_handle = 'kj435kj.lkjlkj.ksdfgdfi44.dsfgkoert908435lkjglgs';
// Refresh the access token using HTTP GET and HMAC-SHA1 signature
$retarr = refresh_access_token(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $old_access_token, $old_token_secret, $oauth_session_handle, false, true, true);
if (!empty($retarr)) {
    list($info, $headers, $body, $body_parsed) = $retarr;
    if ($info['http_code'] == 200 && !empty($body)) {
        print "Use oauth_token as the token for all of your API calls:\n" . rfc3986_decode($body_parsed['oauth_token']) . "\n";
    }
}
exit(0);
/**
 * Refresh an access token using an expired request token
 * @param string $consumer_key obtained when you registered your app
 * @param string $consumer_secret obtained when you registered your app
 * @param string $old_access_token obtained previously
 * @param string $old_token_secret obtained previously
 * @param string $oauth_session_handle obtained previously
 * @param bool $usePost use HTTP POST instead of GET (default false)
 * @param bool $useHmacSha1Sig use HMAC-SHA1 signature (default false)
 * @return response string with token or empty array on error
 */
function refresh_access_token($consumer_key, $consumer_secret, $old_access_token, $old_token_secret, $oauth_session_handle, $usePost = false, $useHmacSha1Sig = true, $passOAuthInHeader = true)
{
    $retarr = array();
Beispiel #4
0
function yim_auth_get_access_token($request_token, $oauth_session_handle = NULL, $oauth_token_secret = NULL)
{
    $url = 'https://api.login.yahoo.com/oauth/v2/get_token';
    $params = yim_get_basic_oauth_params();
    $params['oauth_signature'] = oauth_compute_plaintext_sig(OAUTH_CONSUMER_SECRET, $oauth_token_secret);
    $params['oauth_token'] = $request_token;
    if ($oauth_session_handle != NULL) {
        $params['oauth_session_handle'] = $oauth_session_handle;
    }
    $query_param_string = oauth_http_build_query($params);
    $url = $url . '?' . $query_param_string;
    $response = do_get($url, 443);
    yim_fail_if_not_ok($response, 'Could not get access token');
    $access_token_response = $response[2];
    $access_tokens = split("&", $access_token_response);
    $oauth_data = array();
    foreach ($access_tokens as $param) {
        $d = split("=", $param);
        $oauth_data[$d[0]] = $d[1];
    }
    $oauth_data['oauth_token'] = rfc3986_decode($oauth_data['oauth_token']);
    return $oauth_data;
}
 public function yahooAction()
 {
     require_once "yahooapisrc/globals.php";
     require_once "yahooapisrc/oauth_helper.php";
     $callback = Mage::getStoreConfig('socialapi/yahoo/callbackurl');
     $retarr = $this->get_request_token(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback, true, true, true);
     if (!empty($retarr)) {
         list($info, $headers, $body, $body_parsed) = $retarr;
         $_SESSION['oauth_token_secret'] = $body_parsed['oauth_token_secret'];
         if ($info['http_code'] == 200 && !empty($body)) {
             //print "Have the user go to xoauth_request_auth_url to authorize your app\n" . rfc3986_decode($body_parsed['xoauth_request_auth_url']) . "\n";
             header('Location: ' . rfc3986_decode($body_parsed['xoauth_request_auth_url']));
         }
     }
     exit(0);
 }
Beispiel #6
0
<?php

require_once 'globals.php';
require_once 'oauth_helper.php';
/* Fill in the next 3 variables.*/
$request_token = $_SESSION['request_token'];
$request_token_secret = $_SESSION['request_token_secret'];
$oauth_verifier = $_GET['oauth_verifier'];
/* Get the access token using HTTP GET and HMAC-SHA1 signature */
$retarr = get_access_token_yahoo(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $request_token, $request_token_secret, $oauth_verifier, false, true, true);
if (!empty($retarr)) {
    list($info, $headers, $body, $body_parsed) = $retarr;
    if ($info['http_code'] == 200 && !empty($body)) {
        /*   print "Use oauth_token as the token for all of your API calls:\n" .
             rfc3986_decode($body_parsed['oauth_token']) . "\n"; */
        /* Fill in the next 3 variables. */
        $guid = $body_parsed['xoauth_yahoo_guid'];
        $access_token = rfc3986_decode($body_parsed['oauth_token']);
        $access_token_secret = $body_parsed['oauth_token_secret'];
        /* Call Contact API */
        $retarrs = callcontact_yahoo(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $guid, $access_token, $access_token_secret, false, true);
        echo "<pre/>";
        print_r($retarrs);
    }
}
Beispiel #7
0
<?php

require 'globals.php';
require 'oauth_helper.php';
// Callback can either be 'oob' or a url
$callback = 'oob';
// Get the request token using HTTP GET and HMAC-SHA1 signature
$retarr = get_request_token(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $callback, false, true, true);
if (!empty($retarr)) {
    list($info, $headers, $body, $body_parsed) = $retarr;
    if ($info['http_code'] == 200 && !empty($body)) {
        print "\nHave user surf to\n" . "http://api.twitter.com/oauth/authorize?" . rfc3986_decode($body) . "\n";
    }
}
exit(0);
/**
 * Get a request token.
 * @param string $consumer_key obtained when you registered your app
 * @param string $consumer_secret obtained when you registered your app
 * @param string $callback callback url can be the string 'oob'
 * @param bool $usePost use HTTP POST instead of GET
 * @param bool $useHmacSha1Sig use HMAC-SHA1 signature
 * @param bool $passOAuthInHeader pass OAuth credentials in HTTP header
 * @return array of response parameters or empty array on error
 */
function get_request_token($consumer_key, $consumer_secret, $callback, $usePost = false, $useHmacSha1Sig = true, $passOAuthInHeader = false)
{
    $retarr = array();
    // return value
    $response = array();
    $url = 'http://api.twitter.com/oauth/request_token';
Beispiel #8
0
 public function yahoo()
 {
     require_once "yahooapisrc/globals.php";
     require_once "yahooapisrc/oauth_helper.php";
     $request_token = $_GET['oauth_token'];
     $request_token_secret = $_SESSION['oauth_token_secret'];
     $oauth_verifier = $_GET['oauth_verifier'];
     // Get the access token using HTTP GET and HMAC-SHA1 signature
     $retarr = $this->get_access_token(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $request_token, $request_token_secret, $oauth_verifier, false, true, true);
     if (!empty($retarr)) {
         list($info, $headers, $body, $body_parsed) = $retarr;
         if ($info['http_code'] == 200 && !empty($body)) {
             //print "Use oauth_token as the token for all of your API calls:\n" .
             rfc3986_decode($body_parsed['oauth_token']) . "\n";
         }
     }
     // Fill in the next 3 variables.
     $guid = $body_parsed['xoauth_yahoo_guid'];
     $access_token = rfc3986_decode($body_parsed['oauth_token']);
     $access_token_secret = $body_parsed['oauth_token_secret'];
     // Call Contact API
     $retarr2 = $this->callcontact(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, $guid, $access_token, $access_token_secret, false, true);
     // extract successful response
     if (!empty($retarr2)) {
         list($info, $header, $body) = $retarr2;
         if ($body) {
             $json = json_pretty_print($body);
             $array_contacts = json_decode($json, TRUE);
         }
     }
     $return_contacts = array();
     foreach ($array_contacts['contacts']['contact'] as $yahoo_contact) {
         foreach ($yahoo_contact['fields'] as $field) {
             if ($field['type'] == 'name') {
                 $return_contacts[$yahoo_contact['id']]['name'] = $field['value']['givenName'] . " " . $field['value']['familyName'];
             }
             if ($field['type'] == 'yahooid') {
                 $return_contacts[$yahoo_contact['id']]['email'] = $field['value'] . "@yahoo.com";
             } elseif ($field['type'] == 'otherid') {
                 $return_contacts[$yahoo_contact['id']]['email'] = $field['value'];
             }
         }
     }
     return $return_contacts;
 }
Beispiel #9
0
require 'oauth_helper.php';

// Callback can either be 'oob' or a url whose domain must match
// the domain that you entered when registering your application

$callback='http://dev.americanswan.com/yos-social/examples/mail.php';

// Get the request token using HTTP GET and HMAC-SHA1 signature
$retarr = get_request_token(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET,
                            $callback, false, true, true);

if (! empty($retarr)){
  list($info, $headers, $body, $body_parsed) = $retarr;
  if ($info['http_code'] == 200 && !empty($body)) {
      print "Have the user go to xoauth_request_auth_url to authorize your app\n" .
          rfc3986_decode($body_parsed['xoauth_request_auth_url']) . "\n";
  }
}

exit(0);

/**
 * Get a request token.
 * @param string $consumer_key obtained when you registered your app
 * @param string $consumer_secret obtained when you registered your app
 * @param string $callback callback url can be the string 'oob'
 * @param bool $usePost use HTTP POST instead of GET
 * @param bool $useHmacSha1Sig use HMAC-SHA1 signature
 * @param bool $passOAuthInHeader pass OAuth credentials in HTTP header
 * @return array of response parameters or empty array on error
 */