当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::setBaseUrl方法代码示例

本文整理汇总了PHP中Guzzle\Service\Client::setBaseUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setBaseUrl方法的具体用法?PHP Client::setBaseUrl怎么用?PHP Client::setBaseUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Guzzle\Service\Client的用法示例。


在下文中一共展示了Client::setBaseUrl方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: curl

 /**
  * @param array $data
  * Data that will be sent to the Graph
  *
  * @param string|null $path
  * The path of the request. Some operations like Batch don't need it.
  * If the $path is complete, with all query parameters, $data will be ignored
  *
  * @return \stdClass[]
  */
 public function curl($data = array(), $path = '', $method = 'post')
 {
     $fails = 0;
     $this->guzzle_client->setBaseUrl('https://graph.facebook.com');
     if (substr($path, 0, 26) != 'https://graph.facebook.com') {
         $data['access_token'] = $this->getAccessToken();
     }
     do {
         if ($fails > 0) {
             usleep($fails * 20000 + rand(0, 1000000));
         }
         $result = null;
         switch ($method) {
             case 'get':
                 $path = $this->buildQuery($data, $path);
                 $request = $this->guzzle_client->get($path);
                 break;
             case 'post':
                 foreach ($data as &$data_param) {
                     if (is_array($data_param)) {
                         $data_param = json_encode($data_param);
                     }
                 }
                 $request = $this->guzzle_client->post($path, array(), $data);
                 break;
             default:
                 throw new \Exception('Available methods: post or get');
                 break;
         }
         try {
             $response = $request->send();
         } catch (ClientErrorResponseException $e) {
             throw new OAuthException('Error', 0, $e);
         }
         if ($fails > self::MAX_REQUEST_ATTEMPTS) {
             throw new \Exception('Failed to connect to server ' . self::MAX_REQUEST_ATTEMPTS . ' times');
         }
         $fails++;
         $result = json_decode($response->getBody(true), false, 512, JSON_BIGINT_AS_STRING);
     } while ($this->isNotValidResponse($result));
     if (isset($result->paging) && isset($result->paging->next) && $result->paging->next != null) {
         //$next_result = $this->curl(array(), $result->paging->next, 'get');
         usleep(1000);
         $next_result = $this->curl([], $result->paging->next, 'get');
         /** @noinspection PhpUndefinedFieldInspection */
         $result->data = array_merge($result->data, $next_result->data);
     }
     return $result;
 }
开发者ID:ebussola,项目名称:facebook-core,代码行数:59,代码来源:Core.php

示例2: getVerifiedEmails

 /**
  * Get all the users email addresses
  *
  * @param  string $token
  * @return mixed
  */
 protected function getVerifiedEmails($token)
 {
     $url = 'https://api.github.com/user/emails?access_token=' . $token;
     try {
         $client = new GuzzleClient();
         $client->setBaseUrl($url);
         $request = $client->get()->send();
         $response = $request->getBody();
     } catch (BadResponseException $e) {
         // @codeCoverageIgnoreStart
         $raw_response = explode("\n", $e->getResponse());
         d($raw_response);
         die;
     }
     return json_decode($response);
 }
开发者ID:rajivseelam,项目名称:connect-laravel5-name,代码行数:22,代码来源:Github.php

示例3: setBaseUrl

 /**
  * @param string
  */
 public function setBaseUrl($baseUrl)
 {
     $this->client->setBaseUrl($baseUrl);
 }
开发者ID:cocoiti,项目名称:qiita-php,代码行数:7,代码来源:Qiita.php


注:本文中的Guzzle\Service\Client::setBaseUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。