Beispiel #1
0
 function get_api_endpoint($endpoint)
 {
     if (!$this->store) {
         return "";
     }
     if (!$this->api_endpoints) {
         // this should be replaced with a db lookup...
         $url = 'http://api.typepad.com/api-keys/' . CONSUMER_KEY . '.json';
         $handle = fopen($url, "rb");
         $doc = claire_json_decode(stream_get_contents($handle));
         $owner = $doc->owner;
         $endpoint_strs = array();
         /*
                  ** Links array deprecation happened in R51 (04/2010)
         
         $endpoint_strs['oauth-request-token-endpoint'] = "0";
         $endpoint_strs['oauth-authorization-page'] = "0";
         $endpoint_strs['oauth-access-token-endpoint'] = "0";
         
         
         foreach ($doc->owner->links as $link) {
            foreach (array_keys($endpoint_strs) as $str) {
               if ($link->rel == $str) {
                  $this->api_endpoints[$str] = $link->href;
               }
            }  
         }
         */
         $this->api_endpoints['oauthRequestTokenUrl'] = $doc->owner->oauthRequestTokenUrl;
         $this->api_endpoints['oauthAuthorizationUrl'] = $doc->owner->oauthAuthorizationUrl;
         $this->api_endpoints['oauthAccessTokenUrl'] = $doc->owner->oauthAccessTokenUrl;
     }
     return $this->api_endpoints[$endpoint];
 }
Beispiel #2
0
function post_json($url, $params)
{
    debug("[POST_JSON], URL = <a href='{$url}'>{$url}</a>");
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json;"));
    return claire_json_decode(curl_exec($ch));
}
Beispiel #3
0
<?php

include_once "../oauth/oauth-php-98/library/OAuthStore.php";
include_once "../oauth/oauth-php-98/library/OAuthRequester.php";
include_once 'config.php';
$db_options = array('server' => DB_HOST, 'username' => DB_USERNAME, 'password' => DB_PASSWORD, 'database' => DB_NAME);
$store = OAuthStore::instance('MySQL', $db_options);
/* There should be nothing written to the DB at this point. */
/* 
   Then, make the request to TypePad to get the necessary OAuth URlS. 
*/
$url = 'http://api.typepad.com/api-keys/' . CONSUMER_KEY . '.json';
$handle = fopen($url, "rb");
$doc = claire_json_decode(stream_get_contents($handle));
$owner = $doc->owner;
$endpoint_strs = array();
$endpoint_strs['oauth-request-token-endpoint'] = "0";
$endpoint_strs['oauth-authorization-page'] = "0";
$endpoint_strs['oauth-access-token-endpoint'] = "0";
foreach ($doc->owner->links as $link) {
    foreach (array_keys($endpoint_strs) as $str) {
        if ($link->rel == $str) {
            $endpoint_strs[$str] = $link->href;
        }
    }
}
/*
   Again, still nothing written to the DB at this point.
*/
$server = array('consumer_key' => CONSUMER_KEY, 'consumer_secret' => CONSUMER_SECRET, 'server_uri' => 'http://api.typepad.com/', 'signature_methods' => array('PLAINTEXT'), 'request_token_uri' => $endpoint_strs['oauth-request-token-endpoint'], 'authorize_uri' => $endpoint_strs['oauth-authorization-page'], 'access_token_uri' => $endpoint_strs['oauth-access-token-endpoint']);
//     $user_id = 1;