Exemplo n.º 1
0
/**
 * Call the Yahoo Contact API
 * @param string $consumer_key obtained when you registered your app
 * @param string $consumer_secret obtained when you registered your app
 * @param string $guid obtained from getacctok
 * @param string $access_token obtained from getacctok
 * @param string $access_token_secret obtained from getacctok
 * @param bool $usePost use HTTP POST instead of GET
 * @param bool $passOAuthInHeader pass the OAuth credentials in HTTP header
 * @return response string with token or empty array on error
 */
function call_yql($consumer_key, $consumer_secret, $querynum, $access_token, $access_token_secret, $usePost = false, $passOAuthInHeader = true)
{
    $retarr = array();
    // return value
    $response = array();
    if ($querynum == 1) {
        $url = 'http://query.yahooapis.com/v1/yql';
        // Show my profile
        $params['q'] = 'select * from social.profile where guid=me';
    } elseif ($querynum == 2) {
        $url = 'http://query.yahooapis.com/v1/yql';
        // Find my friends
        $params['q'] = 'select * from social.connections where owner_guid=me';
    } else {
        // Since this information is public, use the non oauth endpoint 'public'
        $url = 'http://query.yahooapis.com/v1/public/yql';
        // Find all sushi restaurants in SF order by number of ratings desc
        $params['q'] = 'select Title,Address,Rating from local.search where query="sushi" and location="san francisco, ca"|sort(field="Rating.TotalRatings",descending="true")';
    }
    $params['format'] = 'json';
    $params['callback'] = 'cbfunc';
    $params['oauth_version'] = '1.0';
    $params['oauth_nonce'] = mt_rand();
    $params['oauth_timestamp'] = time();
    $params['oauth_consumer_key'] = $consumer_key;
    $params['oauth_token'] = $access_token;
    // compute hmac-sha1 signature and add it to the params list
    $params['oauth_signature_method'] = 'HMAC-SHA1';
    $params['oauth_signature'] = oauth_compute_hmac_sig($usePost ? 'POST' : 'GET', $url, $params, $consumer_secret, $access_token_secret);
    // Pass OAuth credentials in a separate header or in the query string
    if ($passOAuthInHeader) {
        $query_parameter_string = oauth_http_build_query($params, true);
        $header = build_oauth_header($params, "yahooapis.com");
        $headers[] = $header;
    } else {
        $query_parameter_string = oauth_http_build_query($params);
    }
    // POST or GET the request
    if ($usePost) {
        $request_url = $url;
        logit("call_yql:INFO:request_url:{$request_url}");
        logit("call_yql:INFO:post_body:{$query_parameter_string}");
        $headers[] = 'Content-Type: application/x-www-form-urlencoded';
        $response = do_post($request_url, $query_parameter_string, 80, $headers);
    } else {
        $request_url = $url . ($query_parameter_string ? '?' . $query_parameter_string : '');
        logit("call_yql:INFO:request_url:{$request_url}");
        $response = do_get($request_url, 80, $headers);
    }
    // extract successful response
    if (!empty($response)) {
        list($info, $header, $body) = $response;
        if ($body) {
            logit("call_yql:INFO:response:");
            print json_pretty_print($body);
        }
        $retarr = $response;
    }
    return $retarr;
}
Exemplo n.º 2
0
/**
* Call twitter to get a list of the user's follow requests
* @param string $access_token obtained from get_request_token
* @param string $access_token_secret obtained from get_request_token
* @return response string or empty array on error
*/
function getFollowers($access_token, $access_token_secret)
{
    $retarr = array();
    // return value
    $response = array();
    //$url = 'http://api.twitter.com/1/statuses/update.json';
    $url = 'http://api.twitter.com/1.1/friendships/incoming.json';
    //$params['status'] = $status_message;
    $params['oauth_version'] = '1.0';
    $params['oauth_nonce'] = mt_rand();
    $params['oauth_timestamp'] = time();
    $params['oauth_consumer_key'] = OAUTH_CONSUMER_KEY;
    $params['oauth_token'] = $access_token;
    // compute hmac-sha1 signature and add it to the params list
    $params['oauth_signature_method'] = 'HMAC-SHA1';
    $params['oauth_signature'] = oauth_compute_hmac_sig('GET', $url, $params, OAUTH_CONSUMER_SECRET, $access_token_secret);
    // Pass OAuth credentials in a separate header or in the query string
    $query_parameter_string = oauth_http_build_query($params, true);
    $header = build_oauth_header($params, "Twitter API");
    $headers[] = $header;
    // POST or GET the request
    $request_url = $url . ($query_parameter_string ? '?' . $query_parameter_string : '');
    //logit("tweet:INFO:request_url:$request_url");
    $response = do_get($request_url, 80, $headers);
    // extract successful response
    if (!empty($response)) {
        list($info, $header, $body) = $response;
        if ($body) {
            //logit("tweet:INFO:response:");
            //print(json_pretty_print($body));
        }
        $retarr = $response;
    }
    return $retarr;
}
Exemplo n.º 3
0
/**
 * Call the Yahoo Contact API
 * @param string $consumer_key obtained when you registered your app
 * @param string $consumer_secret obtained when you registered your app
 * @param string $guid obtained from getacctok
 * @param string $access_token obtained from getacctok
 * @param string $access_token_secret obtained from getacctok
 * @param bool $usePost use HTTP POST instead of GET
 * @param bool $passOAuthInHeader pass the OAuth credentials in HTTP header
 * @return response string with token or empty array on error
 */
function callcontact($consumer_key, $consumer_secret, $guid, $access_token, $access_token_secret, $usePost = false, $passOAuthInHeader = true, $_count)
{
    $retarr = array();
    // return value
    $response = array();
    $url = 'http://social.yahooapis.com/v1/user/' . $guid . '/contacts?count=' . $_count;
    $params['format'] = 'xml';
    $params['view'] = 'compact';
    $params['oauth_version'] = '1.0';
    $params['oauth_nonce'] = mt_rand();
    $params['oauth_timestamp'] = time();
    $params['oauth_consumer_key'] = $consumer_key;
    $params['oauth_token'] = $access_token;
    // compute hmac-sha1 signature and add it to the params list
    $params['oauth_signature_method'] = 'HMAC-SHA1';
    //$params['oauth_signature'] =
    // oauth_compute_hmac_sig($usePost? 'POST' : 'GET', $url, $params,
    // $consumer_secret, $access_token_secret);
    echo ',';
    echo $params['oauth_nonce'];
    echo ',';
    echo $params['oauth_timestamp'];
    echo ',';
    echo oauth_compute_hmac_sig($usePost ? 'POST' : 'GET', $url, $params, $consumer_secret, $access_token_secret);
    exit(0);
    // Pass OAuth credentials in a separate header or in the query string
    if ($passOAuthInHeader) {
        $query_parameter_string = oauth_http_build_query($params, true);
        $header = build_oauth_header($params, "yahooapis.com");
        $headers[] = $header;
    } else {
        $query_parameter_string = oauth_http_build_query($params);
    }
    // POST or GET the request
    if ($usePost && 0) {
        $request_url = $url;
        logit("callcontact:INFO:request_url:{$request_url}");
        logit("callcontact:INFO:post_body:{$query_parameter_string}");
        $headers[] = 'Content-Type: application/x-www-form-urlencoded';
        $response = do_post($request_url, $query_parameter_string, 80, $headers);
    } else {
        $request_url = $url . ($query_parameter_string ? '?' . $query_parameter_string : '');
        logit("callcontact:INFO:request_url:{$request_url}");
        $response = do_get($request_url, 80, $headers);
    }
    // extract successful response
    if (!empty($response)) {
        list($info, $header, $body) = $response;
        if ($body) {
            logit("callcontact:INFO:response:");
            print json_pretty_print($body);
        }
        $retarr = $response;
    }
    return $retarr;
}
Exemplo n.º 4
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();
    // return value
    $response = array();
    $url = 'https://api.login.yahoo.com/oauth/v2/get_token';
    $params['oauth_version'] = '1.0';
    $params['oauth_nonce'] = mt_rand();
    $params['oauth_timestamp'] = time();
    $params['oauth_consumer_key'] = $consumer_key;
    $params['oauth_token'] = $old_access_token;
    $params['oauth_session_handle'] = $oauth_session_handle;
    // compute signature and add it to the params list
    if ($useHmacSha1Sig) {
        $params['oauth_signature_method'] = 'HMAC-SHA1';
        $params['oauth_signature'] = oauth_compute_hmac_sig($usePost ? 'POST' : 'GET', $url, $params, $consumer_secret, $old_token_secret);
    } else {
        $params['oauth_signature_method'] = 'PLAINTEXT';
        $params['oauth_signature'] = oauth_compute_plaintext_sig($consumer_secret, $old_token_secret);
    }
    // Pass OAuth credentials in a separate header or in the query string
    if ($passOAuthInHeader) {
        $query_parameter_string = oauth_http_build_query($params, true);
        $header = build_oauth_header($params, "yahooapis.com");
        $headers[] = $header;
    } else {
        $query_parameter_string = oauth_http_build_query($params);
    }
    // POST or GET the request
    if ($usePost) {
        $request_url = $url;
        logit("refacctok:INFO:request_url:{$request_url}");
        logit("refacctok:INFO:post_body:{$query_parameter_string}");
        $headers[] = 'Content-Type: application/x-www-form-urlencoded';
        $response = do_post($request_url, $query_parameter_string, 443, $headers);
    } else {
        $request_url = $url . ($query_parameter_string ? '?' . $query_parameter_string : '');
        logit("refacctok:INFO:request_url:{$request_url}");
        $response = do_get($request_url, 443, $headers);
    }
    // extract successful response
    if (!empty($response)) {
        list($info, $header, $body) = $response;
        $body_parsed = oauth_parse_str($body);
        if (!empty($body_parsed)) {
            logit("getacctok:INFO:response_body_parsed:");
            print_r($body_parsed);
        }
        $retarr = $response;
        $retarr[] = $body_parsed;
    }
    return $retarr;
}
Exemplo n.º 5
0
 function get_request_token($callback = 'oob', $usePost = false, $useHmacSha1Sig = true, $passOAuthInHeader = false)
 {
     $retarr = array();
     // return value
     $response = array();
     $params['oauth_version'] = '1.0';
     $params['oauth_nonce'] = mt_rand();
     $params['oauth_timestamp'] = time();
     $params['oauth_consumer_key'] = $this->consumer_key;
     $params['oauth_callback'] = $callback;
     $headers = array();
     // compute signature and add it to the params list
     if ($useHmacSha1Sig) {
         $params['oauth_signature_method'] = 'HMAC-SHA1';
         $params['oauth_signature'] = oauth_compute_hmac_sig($usePost ? 'POST' : 'GET', $this->reqUrl, $params, $this->consumer_secret, null);
     } else {
         $params['oauth_signature_method'] = 'PLAINTEXT';
         $params['oauth_signature'] = oauth_compute_plaintext_sig($this->consumer_secret, null);
     }
     // Pass OAuth credentials in a separate header or in the query string
     if ($passOAuthInHeader) {
         $query_parameter_string = oauth_http_build_query($params, true);
         $header = build_oauth_header($params, "Twitter API");
         $headers[] = $header;
     } else {
         $query_parameter_string = oauth_http_build_query($params);
     }
     // POST or GET the request
     if ($usePost) {
         $request_url = $this->reqUrl;
         logit("getreqtok:INFO:request_url:{$request_url}");
         logit("getreqtok:INFO:post_body:{$query_parameter_string}");
         $headers[] = 'Content-Type: application/x-www-form-urlencoded';
         $response = do_post($request_url, $query_parameter_string, 80, $headers);
     } else {
         $request_url = $this->reqUrl . ($query_parameter_string ? '?' . $query_parameter_string : '');
         logit("getreqtok:INFO:request_url:{$request_url}");
         $response = do_get($request_url, 80, $headers);
     }
     // extract successful response
     if (!empty($response)) {
         list($info, $header, $body) = $response;
         $body_parsed = oauth_parse_str($body);
         if (!empty($body_parsed)) {
             logit("getreqtok:INFO:response_body_parsed:");
         }
         $retarr = $response;
         $retarr[] = $body_parsed;
     }
     return $retarr;
 }
Exemplo n.º 6
0
/**
* Call twitter to post a tweet
* @param string $consumer_key obtained when you registered your app
* @param string $consumer_secret obtained when you registered your app
* @param string $status_message
* @param string $access_token obtained from get_request_token
* @param string $access_token_secret obtained from get_request_token
* @param bool $usePost use HTTP POST instead of GET
* @param bool $passOAuthInHeader pass OAuth credentials in HTTP header
* @return response string or empty array on error
*/
function post_tweet($consumer_key, $consumer_secret, $status_message, $access_token, $access_token_secret, $usePost = false, $passOAuthInHeader = true)
{
    $retarr = array();
    // return value
    $response = array();
    //$url = 'http://api.twitter.com/1/statuses/update.json';
    $url = 'http://api.twitter.com/1.1/friendships/incoming.json';
    //$params['status'] = $status_message;
    $params['oauth_version'] = '1.0';
    $params['oauth_nonce'] = mt_rand();
    $params['oauth_timestamp'] = time();
    $params['oauth_consumer_key'] = $consumer_key;
    $params['oauth_token'] = $access_token;
    // compute hmac-sha1 signature and add it to the params list
    $params['oauth_signature_method'] = 'HMAC-SHA1';
    $params['oauth_signature'] = oauth_compute_hmac_sig($usePost ? 'POST' : 'GET', $url, $params, $consumer_secret, $access_token_secret);
    // Pass OAuth credentials in a separate header or in the query string
    if ($passOAuthInHeader) {
        $query_parameter_string = oauth_http_build_query($params, true);
        $header = build_oauth_header($params, "Twitter API");
        $headers[] = $header;
    } else {
        $query_parameter_string = oauth_http_build_query($params);
    }
    // POST or GET the request
    if ($usePost) {
        $request_url = $url;
        logit("tweet:INFO:request_url:{$request_url}");
        logit("tweet:INFO:post_body:{$query_parameter_string}");
        $headers[] = 'Content-Type: application/x-www-form-urlencoded';
        $response = do_post($request_url, $query_parameter_string, 80, $headers);
    } else {
        $request_url = $url . ($query_parameter_string ? '?' . $query_parameter_string : '');
        logit("tweet:INFO:request_url:{$request_url}");
        $response = do_get($request_url, 80, $headers);
    }
    // extract successful response
    if (!empty($response)) {
        list($info, $header, $body) = $response;
        if ($body) {
            logit("tweet:INFO:response:");
            print json_pretty_print($body);
        }
        $retarr = $response;
    }
    return $retarr;
}
Exemplo n.º 7
0
/**
 * Call the Yahoo Contact API
 * @param string $consumer_key obtained when you registered your app
 * @param string $consumer_secret obtained when you registered your app
 * @param string $guid obtained from getacctok
 * @param string $access_token obtained from getacctok
 * @param string $access_token_secret obtained from getacctok
 * @param bool $usePost use HTTP POST instead of GET
 * @param bool $passOAuthInHeader pass the OAuth credentials in HTTP header
 * @return response string with token or empty array on error
 */
function postcontact($consumer_key, $consumer_secret, $guid, $access_token, $access_token_secret, $usePost = false, $passOAuthInHeader = true)
{
    $retarr = array();
    // return value
    $response = array();
    $post_body = '{"contact":{"fields":[{"type":"name","value":{"givenName":"John","middleName":"","familyName":"Doe","prefix":"","suffix":"","givenNameSound":"","familyNameSound":""}},{"type":"email","value":"*****@*****.**"}]}}';
    $url = 'http://social.yahooapis.com/v1/user/' . $guid . '/contacts';
    $params['oauth_version'] = '1.0';
    $params['oauth_nonce'] = mt_rand();
    $params['oauth_timestamp'] = time();
    $params['oauth_consumer_key'] = $consumer_key;
    $params['oauth_token'] = $access_token;
    // compute hmac-sha1 signature and add it to the params list
    $params['oauth_signature_method'] = 'HMAC-SHA1';
    $params['oauth_signature'] = oauth_compute_hmac_sig($usePost ? 'POST' : 'GET', $url, $params, $consumer_secret, $access_token_secret);
    // Pass OAuth credentials in a separate header or in the query string
    if ($passOAuthInHeader) {
        $query_parameter_string = oauth_http_build_query($params, true);
        $header = build_oauth_header($params, "yahooapis.com");
        $headers[] = $header;
        $request_url = $url;
    } else {
        $query_parameter_string = oauth_http_build_query($params);
        $request_url = $url . '?' . $query_parameter_string;
    }
    // POST or GET the request
    if ($usePost) {
        logit("postcontact:INFO:request_url:{$request_url}");
        logit("postcontact:INFO:post_body:{$post_body}");
        $headers[] = 'Content-Type: application/json';
        $response = do_post($request_url, $post_body, 80, $headers);
    } else {
        logit("postcontact:INFO:request_url:{$request_url}");
        $response = do_get($request_url, 80, $headers);
    }
    // extract successful response
    if (!empty($response)) {
        list($info, $header, $body) = $response;
        if ($body) {
            logit("postcontact:INFO:response:");
            print json_pretty_print($body);
        }
        $retarr = $response;
    }
    return $retarr;
}
Exemplo n.º 8
0
 private function apiCall($url, $params = NULL, $oauth_token_secret = NULL, $post = 'POST')
 {
     $params['oauth_version'] = '1.0';
     $params['oauth_nonce'] = mt_rand();
     $params['oauth_timestamp'] = time();
     $params['oauth_consumer_key'] = $this->consumer_key;
     $params['oauth_signature_method'] = 'HMAC-SHA1';
     if ($oauth_token_secret === TRUE) {
         $params['oauth_signature'] = oauth_compute_hmac_sig($post, $url, $params, $this->consumer_secret, null);
     } else {
         $params['oauth_token'] = $this->oauth_token;
         $params['oauth_signature'] = oauth_compute_hmac_sig($post, $url, $params, $this->consumer_secret, $this->oauth_token_secret);
     }
     if (function_exists('curl_init')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_PORT, 80);
         if ($post == 'POST') {
             curl_setopt($ch, CURLOPT_POST, TRUE);
             curl_setopt($ch, CURLOPT_POSTFIELDS, oauth_http_build_query($params));
         } else {
             curl_setopt($ch, CURLOPT_POST, 0);
             $url = $url . '?' . oauth_http_build_query($params);
         }
         curl_setopt($ch, CURLOPT_URL, $url);
         $this->results = curl_exec($ch);
         $this->headerInfo = curl_getinfo($ch);
         curl_close($ch);
         if ($this->headerInfo['http_code'] == 200) {
             return $this->results;
         }
         return FALSE;
     }
     return FALSE;
 }
Exemplo n.º 9
0
/**
* Returns the normalized signature base string of this request
* @param string $http_method
* @param string $url
* @param array $params
* The base string is defined as the method, the url and the
* parameters (normalized), each urlencoded and the concated with &.
* @see http://oauth.net/core/1.0/#rfc.section.A.5.1
*/
function signature_base_string($http_method, $url, $params)
{
    // Decompose and pull query params out of the url
    $query_str = parse_url($url, PHP_URL_QUERY);
    if ($query_str) {
        $parsed_query = oauth_parse_str($query_str);
        // merge params from the url with params array from caller
        $params = array_merge($params, $parsed_query);
    }
    // Remove oauth_signature from params array if present
    if (isset($params['oauth_signature'])) {
        unset($params['oauth_signature']);
    }
    // Create the signature base string. Yes, the $params are double encoded.
    $base_string = rfc3986_encode(strtoupper($http_method)) . '&' . rfc3986_encode(normalize_url($url)) . '&' . rfc3986_encode(oauth_http_build_query($params));
    logit("signature_base_string:INFO:normalized_base_string:{$base_string}");
    return $base_string;
}
Exemplo n.º 10
0
function yim_auth_get_request_token($username, $password)
{
    $url = 'https://login.yahoo.com/WSLogin/V1/get_auth_token';
    $params['oauth_consumer_key'] = OAUTH_CONSUMER_KEY;
    $params['login'] = $username;
    $params['passwd'] = $password;
    $query_param_string = oauth_http_build_query($params);
    $url = $url . '?' . $query_param_string;
    $response = do_get($url, 443);
    yim_fail_if_not_ok($response, 'Invalid credentials');
    $request_token_response = $response[2];
    $request_token_arr = split("=", $request_token_response);
    return $request_token_arr[1];
}
Exemplo n.º 11
0
    /**
     * @private
     */
    function request($request) {
    	
        if(!array_key_exists("content", $request)) {
            $request["content"] = array();
        }
        if(!array_key_exists("query", $request)) {
            $request["query"] = array();
        }

        if(is_array($request["content"])) {
            $combinedParams = array_merge(
                    $request["query"], $request["content"]);
        }
        else {
            $combinedParams = $request["query"];
        }
        $oauthRequest = OAuthRequest::from_consumer_and_token(
                $this->consumer, $this->token, $request["method"],
                $request["url"], $combinedParams);
        $oauthRequest->sign_request($this->signatureMethod, $this->consumer,
                $this->token);
		
        $headers = array("Accept: " . $this->accepts);
        if($this->oauthParamsLocation == OAUTH_PARAMS_IN_HEADERS) {
            $headers[] = $oauthRequest->to_header();
        }
        if(!empty($request["content"]) || $this->oauthParamsLocation == OAUTH_PARAMS_IN_POST_BODY) {
            $headers[] = "Content-Type: " . $request["contentType"];
        }

        if(!empty($request["query"])) {
            $requestUrl = sprintf("%s?%s", $request["url"], oauth_http_build_query($request["query"]));
        }
        else {
            $requestUrl = $request["url"];
        }

        $requestTimeout = array_key_exists("timeout", $request) ?
        $request["timeout"] : $this->defaultTimeout;
		
        $ch = curl_init($requestUrl);
        curl_setopt($ch, CURLOPT_TIMEOUT, $requestTimeout);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $request["method"]);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
        if(($this->oauthParamsLocation == OAUTH_PARAMS_IN_POST_BODY) ||
                (!empty($request["content"]) && is_array($request["content"]))) {
            // Content is an array, URL encode it.
            if($this->oauthParamsLocation == OAUTH_PARAMS_IN_POST_BODY) {
                $request["content"] = $oauthRequest->to_postdata();
                curl_setopt($ch, CURLOPT_POSTFIELDS, $request["content"]);
            }
            else {
                curl_setopt($ch, CURLOPT_POSTFIELDS, oauth_http_build_query($request["content"]));
            }
        }
        else if(!empty($request["content"])) {
            // Content is raw.
            curl_setopt($ch, CURLOPT_POSTFIELDS, $request["content"]);
        }

        // Enable compressed responses from the servers.
        curl_setopt($ch, CURLOPT_ENCODING, "");

        // Set the user agent so the SDK properly identifies itself for
        // usage tracking purposes. Include the version of the SDK and
        // the version of PHP being used.
        $sdkVersion = "1.2";
        $agent = sprintf("YosPhpSdk/%s php/%s", $sdkVersion, phpversion());
        curl_setopt($ch, CURLOPT_USERAGENT, $agent);

        $headerParser = new YahooHeaderParser();
        curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(&$headerParser, "read"));
        
        $response = curl_exec($ch);
        if(is_bool($response) && !$response) {
            YahooLogger::error("Error making libcurl request(" . $requestUrl . "): " . curl_error($ch));
            return NULL;
        }

		
		
        $response = array(
            'method' => $request["method"],
            'url' => $requestUrl,
            'code' => curl_getinfo($ch, CURLINFO_HTTP_CODE),
            'requestHeaders' => $headers,
            'requestBody' => !empty($request["content"]) ? $request["content"] : NULL,
            'responseHeaders' => $headerParser->headers,
            'responseBody' => $response
            );


        if(($response["code"] > 200) && ($response["code"] < 300)) {
            YahooLogger::error("HTTP request failed", $response);

            $this->checkExpired($response["code"], $headerParser);
            return NULL;
        }
        YahooLogger::debug("HTTP request details", $response);

        return $response;
    }
Exemplo n.º 12
0
 public function get_user_profile($type = 'basicprofile', $owner = null)
 {
     global $USER, $SESSION;
     $referring_page = basename($_SERVER['SCRIPT_NAME']) . '?' . $_SERVER['QUERY_STRING'];
     // TODO: check if that really works
     self::check_access_token($referring_page);
     $consumer = self::get_service_consumer();
     if (!$owner) {
         $owner = $USER->get('id');
     }
     if (!empty($consumer->key) && !empty($consumer->secret)) {
         $data = get_record('usr_account_preference', 'usr', $owner, 'field', 'linkedinprofile');
         if ($data) {
             $token = unserialize($data->value);
             switch ($type) {
                 case 'fullprofile':
                     //$fields = ':(first-name,last-name,formatted-name,headline,location:(name),picture-url,picture-urls::(original),public-profile-url,member-url-resources,num-connections,three-current-positions,three-past-positions,summary,specialties,positions,languages,educations,skills,group-memberships)';
                     // SEE: https://developer.linkedin.com/support/developer-program-transition#hero-par_longformtext_longform-text-content-par_resourceparagraph_5
                     $fields = ':(first-name,last-name,formatted-name,headline,location:(name),picture-url,picture-urls::(original),public-profile-url,num-connections,three-current-positions,three-past-positions,summary,specialties,positions,languages,educations,skills,group-memberships)';
                     break;
                 case 'contactinfo':
                     //$fields = ':(first-name,last-name,formatted-name,headline,location:(name),picture-url,picture-urls::(original),public-profile-url,member-url-resources,email-address,phone-numbers,main-address,primary-twitter-account)';
                     // SEE: https://developer.linkedin.com/support/developer-program-transition#hero-par_longformtext_longform-text-content-par_resourceparagraph_5
                     $fields = ':(first-name,last-name,formatted-name,headline,location:(name),picture-url,picture-urls::(original),public-profile-url,email-address)';
                     break;
                 case 'basicprofile':
                 default:
                     $fields = ':(first-name,last-name,formatted-name,headline,location:(name),picture-url,public-profile-url)';
                     break;
             }
             $url = $consumer->apiurl . 'people/~' . $fields;
             $method = 'POST';
             $port = $consumer->ssl ? '443' : '80';
             $params = array('oauth2_access_token' => $token['access_token']);
             $config = array(CURLOPT_URL => $url . '?' . oauth_http_build_query($params), CURLOPT_PORT => $port, CURLOPT_POST => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_CAINFO => dirname(__FILE__) . '/cert/cacert.crt');
             $result = mahara_http_request($config);
             if (isset($result->data) && !empty($result->data) && isset($result->info) && !empty($result->info) && $result->info['http_code'] == 200) {
                 $data = oauth_parse_xml($result->data);
                 return $data;
             } else {
                 $SESSION->add_error_msg(get_string('httprequesterror', 'blocktype.linkedinprofile') . ' ' . $result->info['http_code']);
             }
         } else {
             $SESSION->add_error_msg(get_string('notconnectedtolinkedin', 'blocktype.linkedinprofile'));
         }
     } else {
         throw new ConfigException('Can\'t find LinkedIn api key and/or secret key.');
     }
 }