当前位置: 首页>>代码示例>>PHP>>正文


PHP AdWordsUser::SetOAuth2Handler方法代码示例

本文整理汇总了PHP中AdWordsUser::SetOAuth2Handler方法的典型用法代码示例。如果您正苦于以下问题:PHP AdWordsUser::SetOAuth2Handler方法的具体用法?PHP AdWordsUser::SetOAuth2Handler怎么用?PHP AdWordsUser::SetOAuth2Handler使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AdWordsUser的用法示例。


在下文中一共展示了AdWordsUser::SetOAuth2Handler方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testIntegrationOAuth2Handler_InvalidAccessToken

 /**
  * Tests that the access_token is refreshed correctly and set on the URL
  * params for this client library.
  */
 public function testIntegrationOAuth2Handler_InvalidAccessToken()
 {
     $credentialsOverride = array('access_token' => sprintf('TEST_ACCESS_TOKEN_%s', uniqid()), 'refresh_token' => sprintf('TEST_REFRESH_TOKEN_%s', uniqid()), 'expires_in' => '3600', 'timestamp' => strtotime('-1 day'));
     $credentialsRefreshed = array('access_token' => sprintf('TEST_ACCESS_TOKEN_%s', uniqid()), 'refresh_token' => $credentialsOverride['refresh_token'], 'expires_in' => '3600', 'timestamp' => time(), 'Foo' => 'bar');
     // Get the response xml
     $xmlResponse = $this->assetHelper->getAsset(sprintf(self::RESPONSE_NAME, self::SERVICE));
     // Create a regular AdWordsUser
     $user = new AdWordsUser($this->assetHelper->getAssetPath('auth.ini'));
     $campaignService = $user->getService(self::SERVICE);
     $oAuth2Info = $user->GetOAuth2Info();
     $newOAuth2Info = array_merge($oAuth2Info, $credentialsOverride);
     $user->SetOAuth2Info($newOAuth2Info);
     // Get the expected auth param for the URL.
     $oauth2Url = http_build_query(array('access_token' => $credentialsRefreshed['access_token']));
     // Setup the mocked OAuth2Handler class.
     $oAuth2Handler = $this->getMock('SimpleOAuth2Handler', array('RefreshAccessToken'));
     $oAuth2Handler->expects($this->any())->method('RefreshAccessToken')->will($this->returnValue($credentialsRefreshed));
     $user->SetOAuth2Handler($oAuth2Handler);
     // Setup the test.
     $soapClientMock = $this->getMockBuilder('SoapClient')->setMethods(array('__doRequest'))->disableOriginalConstructor()->getMock();
     // Checking for the URL param for the auth token
     // (passed in the second function param)
     $soapClientMock->expects($this->any())->method('__doRequest')->with($this->anything(), $this->stringContains($oauth2Url))->will($this->returnValue($xmlResponse));
     // Set the transport layer on the soap client to be the mocked soap client.
     $campaignService->__SetTransportLayer($soapClientMock);
     // Create selector.
     $selector = new Selector();
     // Specify the fields to retrieve.
     $selector->fields = array('Login', 'CustomerId', 'Name');
     // Make the get request.
     $campaignService->get($selector);
 }
开发者ID:phobik,项目名称:google-api-adwords-php,代码行数:36,代码来源:AdWordsIntegrationTest.php


注:本文中的AdWordsUser::SetOAuth2Handler方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。