post() public method

Call API with a POST request. Returns either false on failure or an HttpResponse object.
public post ( $accessTokenKey, $accessTokenSecret, $url, array $postData = [] )
$postData array
Ejemplo n.º 1
0
 /**
  * Sends the message to the configured network
  *
  * @param string $pPostBody
  * @return mixed
  */
 protected function send($pPostBody)
 {
     $this->onlineIdentity->scheduleImportJob();
     $lToken = $this->getAuthToken();
     $lKey = sfConfig::get("app_" . $this->classToIdentifier() . "_oauth_token");
     $lSecret = sfConfig::get("app_" . $this->classToIdentifier() . "_oauth_secret");
     $lPostApi = sfConfig::get("app_" . $this->classToIdentifier() . "_post_api");
     $lPostRealm = sfConfig::get("app_" . $this->classToIdentifier() . "_post_realm");
     $lPostType = ($pt = sfConfig::get("app_" . $this->classToIdentifier() . "_post_type")) ? array($pt) : null;
     $lConsumer = new OAuthConsumer($lKey, $lSecret);
     return OAuthClient::post($lConsumer, $lToken->getTokenKey(), $lToken->getTokenSecret(), $lPostApi, $pPostBody, null, $lPostType, $lPostRealm);
 }
Ejemplo n.º 2
0
 /**
  * add identifier
  *
  * @author Matthias Pfefferle
  * @param User $pUser
  * @param AuthToken $pAuthToken
  * @return OnlineIdentity
  */
 public function addIdentifier($user, $pOAuthToken)
 {
     $lAccessToken = $this->getAccessToken($pOAuthToken);
     //var_dump($lAccessToken);die();
     // get params
     $lParams = $lAccessToken->params;
     $lParamsArray = array();
     // extract params
     parse_str($lParams, $lParamsArray);
     //$lConsumer = new OAuthConsumer(sfConfig::get("app_linkedin_oauth_token"), sfConfig::get("app_linkedin_oauth_secret"));
     $json = OAuthClient::post($this->getConsumer(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], "http://api.tumblr.com/v2/user/info");
     $json = json_decode($json, true);
     foreach ($json['response']['user']['blogs'] as $blog) {
         $user_name = $blog['name'];
         $auth_identifier = "http://" . $user_name . ".tumblr.com";
         // ask for online identity
         $online_identity = OnlineIdentityTable::retrieveByAuthIdentifier($auth_identifier);
         // check if user already exists
         if ($online_identity) {
             if ($online_identity->getUserId() && $user->getId() == $online_identity->getUserId()) {
                 if (!$online_identity->getActive()) {
                     $online_identity->setActive(true);
                 } else {
                     //throw new sfException("online identity already added", 1);
                     continue;
                 }
             } elseif ($online_identity->getUserId() && $user->getId() != $online_identity->getUserId()) {
                 //throw new sfException("online identity already added by someone else", 2);
                 continue;
             }
         } else {
             // check online identity
             $online_identity = OnlineIdentityTable::addOnlineIdentity($auth_identifier, $user_name, $this->aCommunityId);
         }
         $this->completeOnlineIdentity($online_identity, $blog, $user, $auth_identifier);
         // save new token
         AuthTokenTable::saveToken($user->getId(), $online_identity->getId(), $lParamsArray['oauth_token'], $lParamsArray['oauth_token_secret'], true);
     }
     return $user;
 }
Ejemplo n.º 3
0
    function getAccessTokenProxy($consumerKey, $consumerSecret, $requestToken, $verifier) {
        global $YahooConfig;

        $request_url = sprintf("https://%s/oauth/v2/get_token", $YahooConfig["OAUTH_HOSTNAME"]);

        $consumer = new OAuthConsumer($consumerKey, $consumerSecret);

        $parameters = array();
		if(!$requestToken){
            return false;
        }
        if(property_exists($requestToken, "sessionHandle")) {
            $parameters["oauth_session_handle"] = $requestToken->sessionHandle;
        }

        if(!is_null($verifier)) {
            $parameters["oauth_verifier"] = $verifier;
        }

        $client = new OAuthClient($consumer, $requestToken, OAUTH_PARAMS_IN_POST_BODY);

        $response = $client->post($request_url, "application/x-www-form-urlencoded", $parameters);

        if(is_null($response)) {
            YahooLogger::error("OAuth call to get access token failed");
            return NULL;
        }

        parse_str($response["responseBody"], $token);

        if($response["code"] != 200) {
            YahooLogger::error("Failed to fetch access token: " . $token["oauth_problem"]);
            return NULL;
        }

        $now = time();

        $accessToken = new stdclass();
        $accessToken->key = $token["oauth_token"];
        $accessToken->secret = $token["oauth_token_secret"];
        $accessToken->guid = $token["xoauth_yahoo_guid"];
        $accessToken->consumer = $consumerKey;
        $accessToken->sessionHandle = $token["oauth_session_handle"];

        // Check to see if the access token ever expires.
        YahooLogger::debug('AT expires in '.$token['oauth_expires_in'].'; ASH expires in '.$token["oauth_authorization_expires_in"]);
        if(array_key_exists("oauth_expires_in", $token)) {
            $accessToken->tokenExpires = $now + $token["oauth_expires_in"];
        }
        else {
            $accessToken->tokenExpires = -1;
        }

        // Check to see if the access session handle ever expires.
        if(array_key_exists("oauth_authorization_expires_in", $token)) {
            $accessToken->handleExpires = $now +
                    $token["oauth_authorization_expires_in"];
        }
        else {
            $accessToken->handleExpires = -1;
        }
        return $accessToken;
    }
Ejemplo n.º 4
0
 $response = $storage->get($storageKey);
 $value = json_decode($response->value);
 // session store interface defined in Yahoo! SDK
 $yahooSdkSessionStore = new CustomSessionStore($storage, $storageKey);
 //use oauth consumer to sign request for access token
 $consumer = new OAuthConsumer($value->consumerKey, $value->consumerSecret);
 //format request token as expected by oauth lib
 $requestToken = new stdclass();
 $requestToken->key = $input['requestToken'];
 //ref: http://step2.googlecode.com/svn/spec/openid_oauth_extension/latest/openid_oauth_extension.html#AuthTokenReq
 $requestToken->secret = '';
 //client defined in Yahoo! SDK
 $client = new OAuthClient($consumer, $requestToken, OAUTH_PARAMS_IN_POST_BODY);
 //$YahooConfig["OAUTH_HOSTNAME"] defined in Yahoo! SDK
 $uri = sprintf("https://%s/oauth/v2/get_token", $YahooConfig["OAUTH_HOSTNAME"]);
 $response = $client->post($uri);
 parse_str($response["responseBody"], $params);
 $now = time();
 $accessToken = new stdclass();
 //note: key is oauth access token.
 //kludge: suspecting php bug - 1st array elem inaccesible by key.
 $accessToken->key = array_shift($params);
 $accessToken->secret = $params["oauth_token_secret"];
 $accessToken->guid = $params["xoauth_yahoo_guid"];
 //note: consumer is the app key
 $accessToken->consumer = $value->consumerKey;
 $accessToken->sessionHandle = $params["oauth_session_handle"];
 // Check to see if the access token ever expires.
 if (array_key_exists("oauth_expires_in", $params)) {
     $accessToken->tokenExpires = $now + $params["oauth_expires_in"];
 } else {