本文整理汇总了PHP中Guzzle\Http\ClientInterface::setDefaultOption方法的典型用法代码示例。如果您正苦于以下问题:PHP ClientInterface::setDefaultOption方法的具体用法?PHP ClientInterface::setDefaultOption怎么用?PHP ClientInterface::setDefaultOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\ClientInterface
的用法示例。
在下文中一共展示了ClientInterface::setDefaultOption方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: enableOAuth2Authentication
public function enableOAuth2Authentication($clientId, $clientSecret, $accessToken, $refreshToken)
{
$this->clientId = $clientId;
$this->clientSecret = $clientSecret;
$this->accessToken = $accessToken;
$this->refreshToken = $refreshToken;
$this->client->setDefaultOption('request.options/headers/Authorization', 'Bearer ' . $this->accessToken);
}
示例2: __construct
/**
* @param string $accessToken
* @param ClientInterface $client (optional)
* @param ExceptionInterface $exception (optional)
*/
public function __construct($accessToken, ClientInterface $client = null, ExceptionInterface $exception = null)
{
$that = $this;
$this->client = $client ?: new Client();
$this->exception = $exception;
$this->client->setDefaultOption('headers/Authorization', sprintf('Bearer %s', $accessToken))->setDefaultOption('events/request.complete', function (Event $event) use($that) {
$that->handleResponse($event);
$event->stopPropagation();
});
}
示例3: enableOauthAuthentication
public function enableOauthAuthentication($key, $secret, $accessToken = null, $code = null)
{
$this->key = $key;
$this->secret = $secret;
$this->accessToken = $accessToken;
$this->code = $code;
if (!$accessToken && !$code) {
throw new InvalidArgumentException(sprintf("No OAuth code or access token given, please visit %s to generate a new code", "https://www.dropbox.com/1/oauth2/authorize?response_type=code&client_id={$key}"));
} elseif (!$accessToken && $code) {
$request = $this->client->post('oauth2/token', array(), array('code' => $this->code, 'grant_type' => 'authorization_code', 'client_id' => $this->key, 'client_secret' => $this->secret));
try {
$response = $request->send();
} catch (ClientErrorResponseException $e) {
$this->handleBadResponseExceptions($e);
}
$token = $response->json();
$this->accessToken = $token['access_token'];
}
$this->client->setDefaultOption('request.options/headers/Authorization', 'Bearer ' . $this->accessToken);
}
示例4: enableTokenAuthentication
/**
* Add the token authentication as default header to the client.
*/
public function enableTokenAuthentication($token)
{
$this->client->setDefaultOption('request.options/headers/Authorization', 'token ' . $token);
}
示例5: __construct
/**
* @param string $token
* @param ClientInterface|null $client
*/
public function __construct($token, ClientInterface $client = null)
{
$this->client = $client ?: new Client();
$this->client->setDefaultOption('headers/Authorization', sprintf('Bearer %s', $token));
}
示例6: __construct
/**
* Constructor.
*
* @param string $token Access Token
* @param ClientInterface|null $client Client Instance
*/
public function __construct($token, ClientInterface $client = null)
{
$this->client = $client ?: new Client();
$this->client->setDefaultOption('headers/access_token', $token);
}