本文整理匯總了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);
}