本文整理汇总了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;
}
示例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);
}
示例3: setBaseUrl
/**
* @param string
*/
public function setBaseUrl($baseUrl)
{
$this->client->setBaseUrl($baseUrl);
}