コード例 #1
0
 public function getConsumer()
 {
     if ($this->consumer) {
         return $this->consumer;
     }
     $consumer = new Consumer($this->getOptions());
     //to void the error :  make sure the "sslcapath" option points to a valid SSL certificate directory
     $consumer->getHttpClient()->setOptions(array('sslverifypeer' => false));
     return $this->consumer = $consumer;
 }
コード例 #2
0
 /**
  * @return bool|NormalizedData
  */
 public function getUserData()
 {
     if ($this->data) {
         return $this->data;
     }
     $config = array('consumerKey' => $this->consumerKey, 'consumerSecret' => $this->consumerSecret, 'siteUrl' => 'https://api.twitter.com/oauth');
     $httpClientOptions = array('adapter' => 'Zend\\Http\\Client\\Adapter\\Curl', 'curloptions' => array(CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false));
     $consumer = new Consumer($config);
     $consumer->setHttpClient($consumer->getHttpClient()->setOptions($httpClientOptions));
     $tw_session = new Container('twitter');
     if (!empty($this->getParams) && $tw_session->offsetExists('request_token')) {
         try {
             $tw_request_token = $tw_session->offsetGet('request_token');
             $token = $consumer->getAccessToken($this->getParams, unserialize($tw_request_token));
             $tw_session->offsetUnset('request_token');
             $client = $token->getHttpClient($config, null, array('adapter' => new Client\Adapter\Curl()));
             $client->setUri('https://api.twitter.com/1.1/account/verify_credentials.json');
             $client->setMethod(Request::METHOD_GET);
             $adapter = new Client\Adapter\Curl();
             $adapter->setCurlOption(CURLOPT_SSL_VERIFYHOST, false);
             $adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
             $client->setAdapter($adapter);
             $response = $client->send();
             $data = Json::decode($response->getBody(), Json::TYPE_ARRAY);
             $data['token'] = serialize($token);
             $this->isValid = true;
             return new NormalizedData(NormalizedData::PROVIDER_TYPE_TWITTER, $data);
         } catch (\Exception $e) {
             return false;
         }
     }
     return false;
 }