本文整理汇总了PHP中Google_Client::setHttpClient方法的典型用法代码示例。如果您正苦于以下问题:PHP Google_Client::setHttpClient方法的具体用法?PHP Google_Client::setHttpClient怎么用?PHP Google_Client::setHttpClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Google_Client
的用法示例。
在下文中一共展示了Google_Client::setHttpClient方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createClient
private function createClient()
{
$options = ['auth' => 'google_auth', 'exceptions' => false];
if ($proxy = getenv('HTTP_PROXY')) {
$options['proxy'] = $proxy;
$options['verify'] = false;
}
// adjust constructor depending on guzzle version
if (!$this->isGuzzle6()) {
$options = ['defaults' => $options];
}
$httpClient = new GuzzleHttp\Client($options);
$client = new Google_Client();
$client->setApplicationName('google-api-php-client-tests');
$client->setHttpClient($httpClient);
$client->setScopes(["https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/urlshortener", "https://www.googleapis.com/auth/tasks", "https://www.googleapis.com/auth/adsense", "https://www.googleapis.com/auth/youtube", "https://www.googleapis.com/auth/drive"]);
if ($this->key) {
$client->setDeveloperKey($this->key);
}
list($clientId, $clientSecret) = $this->getClientIdAndSecret();
$client->setClientId($clientId);
$client->setClientSecret($clientSecret);
$client->setCache($this->getCache());
return $client;
}
示例2: testPrepareService
public function testPrepareService()
{
$client = new Google_Client();
$client->setScopes(array("scope1", "scope2"));
$scopes = $client->prepareScopes();
$this->assertEquals("scope1 scope2", $scopes);
$client->setScopes(array("", "scope2"));
$scopes = $client->prepareScopes();
$this->assertEquals(" scope2", $scopes);
$client->setScopes("scope2");
$client->addScope("scope3");
$client->addScope(array("scope4", "scope5"));
$scopes = $client->prepareScopes();
$this->assertEquals("scope2 scope3 scope4 scope5", $scopes);
$client->setClientId('test1');
$client->setRedirectUri('http://localhost/');
$client->setState('xyz');
$client->setScopes(array("http://test.com", "scope2"));
$scopes = $client->prepareScopes();
$this->assertEquals("http://test.com scope2", $scopes);
$this->assertEquals('' . 'https://accounts.google.com/o/oauth2/auth' . '?response_type=code' . '&access_type=online' . '&client_id=test1' . '&redirect_uri=http%3A%2F%2Flocalhost%2F' . '&state=xyz' . '&scope=http%3A%2F%2Ftest.com%20scope2' . '&approval_prompt=auto', $client->createAuthUrl());
$response = $this->getMock('Psr\\Http\\Message\\ResponseInterface');
$response->expects($this->once())->method('getBody')->will($this->returnValue($this->getMock('Psr\\Http\\Message\\StreamInterface')));
$http = $this->getMock('GuzzleHttp\\ClientInterface');
$http->expects($this->once())->method('send')->will($this->returnValue($response));
if ($this->isGuzzle5()) {
$guzzle5Request = new GuzzleHttp\Message\Request('POST', '/');
$http->expects($this->once())->method('createRequest')->will($this->returnValue($guzzle5Request));
}
$client->setHttpClient($http);
$dr_service = new Google_Service_Drive($client);
$this->assertInstanceOf('Google_Model', $dr_service->files->listFiles());
}
示例3: testNoExpectedClassForAltMediaWithHttpFail
public function testNoExpectedClassForAltMediaWithHttpFail()
{
// set the "alt" parameter to "media"
$arguments = [['alt' => 'media']];
$request = new Request('GET', '/?alt=media');
$body = Stream::factory('thisisnotvalidjson');
$response = new Response(300, [], $body);
$http = $this->getMockBuilder("GuzzleHttp\\Client")->disableOriginalConstructor()->getMock();
$http->expects($this->once())->method('send')->will($this->returnValue($response));
$http->expects($this->any())->method('createRequest')->will($this->returnValue(new Request('GET', '/?alt=media')));
$http->expects($this->once())->method('send')->will($this->returnValue($response));
$client = new Google_Client();
$client->setHttpClient($http);
$service = new Test_Google_Service($client);
// set up mock objects
$resource = new Google_Service_Resource($service, "test", "testResource", array("methods" => array("testMethod" => array("parameters" => array(), "path" => "method/path", "httpMethod" => "POST"))));
try {
$expectedClass = 'ThisShouldBeIgnored';
$decoded = $resource->call('testMethod', $arguments, $expectedClass);
$this->fail('should have thrown exception');
} catch (Google_Service_Exception $e) {
$this->assertEquals('thisisnotvalidjson', $e->getMessage());
}
}
示例4: testExceptionMessage
public function testExceptionMessage()
{
// set the "alt" parameter to "media"
$request = new Request('GET', '/');
$errors = [["domain" => "foo"]];
$body = Psr7\stream_for(json_encode(['error' => ['errors' => $errors]]));
$response = new Response(400, [], $body);
$http = $this->getMockBuilder("GuzzleHttp\\Client")->disableOriginalConstructor()->getMock();
$http->expects($this->once())->method('send')->will($this->returnValue($response));
if ($this->isGuzzle5()) {
$http->expects($this->once())->method('createRequest')->will($this->returnValue(new GuzzleHttp\Message\Request('GET', '/?alt=media')));
}
$client = new Google_Client();
$client->setHttpClient($http);
$service = new Test_Google_Service($client);
// set up mock objects
$resource = new Google_Service_Resource($service, "test", "testResource", array("methods" => array("testMethod" => array("parameters" => array(), "path" => "method/path", "httpMethod" => "POST"))));
try {
$decoded = $resource->call('testMethod', array(array()));
$this->fail('should have thrown exception');
} catch (Google_Service_Exception $e) {
$this->assertEquals($errors, $e->getErrors());
}
}