本文整理匯總了PHP中Google_HttpRequest::setUrl方法的典型用法代碼示例。如果您正苦於以下問題:PHP Google_HttpRequest::setUrl方法的具體用法?PHP Google_HttpRequest::setUrl怎麽用?PHP Google_HttpRequest::setUrl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Google_HttpRequest
的用法示例。
在下文中一共展示了Google_HttpRequest::setUrl方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: sign
public function sign(Google_HttpRequest $request)
{
if ($this->key) {
$request->setUrl($request->getUrl() . (strpos($request->getUrl(), '?') === false ? '?' : '&') . 'key=' . urlencode($this->key));
}
return $request;
}
示例2: sign
/**
* Include an accessToken in a given apiHttpRequest.
* @param Google_HttpRequest $request
* @return Google_HttpRequest
* @throws Google_AuthException
*/
public function sign(Google_HttpRequest $request)
{
// add the developer key to the request before signing it
if ($this->developerKey) {
$requestUrl = $request->getUrl();
$requestUrl .= strpos($request->getUrl(), '?') === false ? '?' : '&';
$requestUrl .= 'key=' . urlencode($this->developerKey);
$request->setUrl($requestUrl);
}
// Cannot sign the request without an OAuth access token.
if (null == $this->token && null == $this->assertionCredentials) {
return $request;
}
// Check if the token is set to expire in the next 30 seconds
// (or has already expired).
if ($this->isAccessTokenExpired()) {
if ($this->assertionCredentials) {
$this->refreshTokenWithAssertion();
} else {
if (!array_key_exists('refresh_token', $this->token)) {
throw new Google_AuthException("The OAuth 2.0 access token has expired, " . "and a refresh token is not available. Refresh tokens are not " . "returned for responses that were auto-approved.");
}
$this->refreshToken($this->token['refresh_token']);
}
}
// Add the OAuth2 header to the request
$request->setRequestHeaders(array('Authorization' => 'Bearer ' . $this->token['access_token']));
return $request;
}