Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

6.0 #7

Merged
merged 2 commits into from Jun 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 8 additions & 4 deletions ReadMe.md
@@ -1,6 +1,10 @@
# スポンサードサーチAPI PHPサンプルプログラム
スポンサードサーチAPI Ver.5.3向けのPHPサンプルプログラムです。<br>
ご利用前に、以下のReadMeをご確認ください。
スポンサードサーチAPI Ver.6.0向けのPHPサンプルプログラムです。<br>
ご利用前に、以下のreadmeをご確認ください。<br>
### [日本語 (Japanese)](./readme_JA.txt)

### [日本語](./readme_JA.txt)
### [英語](./readme_EN.txt)

# Sponsored Search API PHP Sample Program
This is PHP Sample Program for Sponsored Search Ver.6.0.<br>
Please confiorm the readme below before using.
### [English](./readme_EN.txt)
7 changes: 6 additions & 1 deletion readme_EN.txt
Expand Up @@ -5,6 +5,9 @@ Version 6.0.0

[Change history]
-----------
2016/05/13:
- Add CampaignExportSample at Version 6.0.

2016/04/13:
- Correspond to Version 6.0.

Expand Down Expand Up @@ -75,14 +78,15 @@ The following programs are stored.
- siteRetargetingSample/SiteRetargetingSample.php : Sample of Get and Mutate operation for site retargeting function via RetargetingListService/BiddingStrategyService/CampaignService/NegativeCampaignRetargetingListService/AdGroupService/AdGroupRetargetingListService.
- targetingIdeaSample/TargetingIdeaSample.php : Sample of Get the related keywords based on the specified value via TargetingIdeaService.
- trafficEstimatorSample/TrafficEstimatorSample.php : Sample of Get the estimate keyword data of the selected keyword via KeywordEstimatorService.
- campaignExportSample/CampaignExportSample.java : Sample of Add the export job and Download via CampaignExportService.

* Class is used from sample programs below.

- Service.class.php : It is a sample class added setting process in RequestHeader by extending SoapClient.
- SoapUtils.class.php : It is a sample for the process via LocationService and the common process.

[download directory]
It stores the downloded file when you execute ReportDownloadSample.
It stores the downloded file when you execute ReportDownloadSample,CampaignExportSample.

[upload directory]
Currently not available.
Expand Down Expand Up @@ -163,6 +167,7 @@ php src/siteRetargetingSample/RetargetingListServiceSample.php
php src/siteRetargetingSample/SiteRetargetingSample.php
php src/targetingIdeaSample/TargetingIdeaSample.php
php src/trafficEstimatorSample/TrafficEstimatorSample.php
php src/campaignExportSample/CampaignExportSample.php
---------------------------------------

When the operation for data download is executed, the file will be stored in the directory of download.
7 changes: 6 additions & 1 deletion readme_JA.txt
Expand Up @@ -5,6 +5,9 @@ Version 6.0.0

■変更履歴
-----------
2016/05/13:
- CampaignExportSample(Version 6.0)を追加しました。

2016/04/13:
- Version 6.0に対応しました。

Expand Down Expand Up @@ -75,14 +78,15 @@ PHPのSoapClientライブラリを使用してAPIを呼び出す形になって
- siteRetargetingSample/SiteRetargetingSample.php : RetargetingListService/BiddingStrategyService/CampaignService/NegativeCampaignRetargetingListService/AdGroupService/AdGroupRetargetingListServiceによるサイトリターゲティング機能の登録、参照、更新、削除処理のサンプルです。
- targetingIdeaSample/TargetingIdeaSample.php : TargetingIdeaServiceによる推奨キーワードを参照する処理のサンプルです。
- trafficEstimatorSample/TrafficEstimatorSample.php : TrafficEstimatorServiceによる指定キーワードのクリック単価や掲載順位などの予測値を参照する処理のサンプルです。
- campaignExportSample/CampaignExportSample.php : CampaignExportServiceによるExportジョブ登録、CSVダウンロードのサンプルです。

・以下は各サンプルプログラムから利用されるクラスです。

- Service.class.php :SoapClientを拡張してRequestHeaderの設定処理を追加したクラスのサンプルです。
- SoapUtils.class.php :LocationServiceを使用したリクエスト先の取得処理のサンプル及びその他共通処理です。

■downloadディレクトリ
ReportDownloadSampleを実行した際に、ダウンロードしたデータがファイルとして格納されるディレクトリです。
ReportDownloadSample,CampaignExportSampleを実行した際に、ダウンロードしたデータがファイルとして格納されるディレクトリです。

■uploadディレクトリ
現在は利用しません。
Expand Down Expand Up @@ -163,6 +167,7 @@ php src/siteRetargetingSample/RetargetingListServiceSample.php
php src/siteRetargetingSample/SiteRetargetingSample.php
php src/targetingIdeaSample/TargetingIdeaSample.php
php src/trafficEstimatorSample/TrafficEstimatorSample.php
php src/campaignExportSample/CampaignExportSample.php
---------------------------------------

データをダウンロードする処理を実行した場合には、downloadディレクトリにファイルが格納されます。
155 changes: 155 additions & 0 deletions src/campaignExportSample/CampaignExportSample.php
@@ -0,0 +1,155 @@
<?php
require_once (dirname(__FILE__) . '/../../conf/api_config.php');
require_once (dirname(__FILE__) . '/../util/SoapUtils.class.php');

/**
* Sample Program for CampaingExportService.
* Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
*/

class CampaignExportSample{
private $serviceName = 'CampaignExportService';

private $service;

private $jodId;

private $jobName;

private $downloadUrl;

public function __construct(){
$this->service = SoapUtils::getService($this->serviceName);

}

/**
* execute CampaignExportService::addJob
* @param array $exportSetting
* @throws Exception
*/
public function addJob($exportSetting){
$response = $this->service->invoke('addJob', $exportSetting);

if(isset($response->rval->values)){
if(isset($response->rval->values->job) && !isset($response->rval->values->error)){
$this->jodId = $response->rval->values->job->jobId;
$this->jobName = $response->rval->values->job->jobName;
}else{
throw new Exception('addJob Error. ' . $this->serviceName);
}
}else{
throw new Exception('No response of addJob ' . $this->serviceName . '.');
}
}

/**
* execute CampaignExportService::get
* @param array $selector
* @throws Exception
*/
public function get($selector){

for($i = 0; $i < 30; $i++){
$response = $this->service->invoke('get', $selector);
if(isset($response->rval->values)){
if(isset($response->rval->values->job) && !isset($response->rval->values->error)){
$status = $response->rval->values->job->status;
if($status === 'COMPLETED'){
$this->jodId = $response->rval->values->job->jobId;
$this->jobName = $response->rval->values->job->jobName;
$this->downloadUrl = $response->rval->values->job->downloadUrl;
break;
}else if($status === 'SYSTEM_ERROR'){
throw new Exception('export job Error. ' . $this->serviceName);
}
}else{
throw new Exception('get Error. ' . $this->serviceName);
}
}else{
throw new Exception('No response of get ' . $this->serviceName . '.');
}

// sleep 10 second.
echo "\n***** sleep 10 seconds for Export Job *****\n";
sleep(10);
}

if(is_null($this->downloadUrl)){
throw new Exception('export job Timeout. ' . $this->serviceName);
}

}

/**
* execute CampaignExportService::download
*/
public function download(){
$fileName = 'CampaignExport_' . $this->jobName . '_' . $this->jodId . '.csv';
SoapUtils::download($this->downloadUrl, $fileName);
}

public function getJobId(){
return $this->jodId;
}

public function getJobName(){
return $this->jobName;
}

public function getDownloadUrl(){
return $this->downloadUrl;
}

}

if(__FILE__ != realpath($_SERVER['PHP_SELF'])){
return;
}

/**
* execute CampaignExportServiceSample.
*/
try{
$campaignExportSample = new CampaignExportSample();

// =================================================================
// CampaignExportService addJob
// =================================================================
$exportSetting = array(
'setting' => array(
'accountId' => SoapUtils::getAccountId(),
'jobName' => 'sampleExport',
'advanced' => 'FALSE',
'entityTypes' => array('CAMPAIGN','BIDDABLE_AD_GROUP_CRITERION'),
'lang' => 'EN',
'output' => 'CSV',
'encoding' => 'UTF-8'
)
);

$campaignExportSample->addJob($exportSetting);


// =================================================================
// CampaignExportService get
// =================================================================
$selector = array(
'selector' => array(
'accountId' => SoapUtils::getAccountId(),
'jobIds' => array($campaignExportSample->getJobId())
)
);

$campaignExportSample->get($selector);


// =================================================================
// CampaignExportService download
// =================================================================
$campaignExportSample->download();


}catch (Exception $e){
printf($e->getMessage() . "\n");
}
Expand Up @@ -324,4 +324,4 @@ public function createSampleSetRequest($accountId, $conversionTrackerValues){

}catch(Exception $e){
printf($e->getMessage() . "\n");
}
}
2 changes: 1 addition & 1 deletion src/customerSyncSample/CustomerSyncSample.php
Expand Up @@ -49,4 +49,4 @@
}else{
echo 'Fail to get Auditlog.';
exit();
}
}
2 changes: 1 addition & 1 deletion src/dictionarySample/DictionarySample.php
Expand Up @@ -46,4 +46,4 @@
if(!isset($getGeographicLocationResponse->rval->values)){
echo 'Fail to getGeographicLocation.';
exit();
}
}
2 changes: 1 addition & 1 deletion src/keywordEstimatorSample/KeywordEstimatorSample.php
Expand Up @@ -57,4 +57,4 @@
if(!isset($getKeywordEstimatorResponse->rval->values)){
echo 'Fail to get KeywordEstimator.';
exit();
}
}
28 changes: 15 additions & 13 deletions src/reportDownloadSample/ReportDownloadSample.php
Expand Up @@ -56,18 +56,20 @@
'operator' => 'ADD',
'accountId' => SoapUtils::getAccountId(),
'operand' => array(
'accountId' => SoapUtils::getAccountId(),
'reportName' => 'ACCOUNT-REPORT',
'reportType' => 'ACCOUNT',
'dateRangeType' => 'YESTERDAY',
'sort' => '+' . $fields[0],
'fields' => $fields,
'compress' => 'NONE',
'isTemplate' => 'TRUE',
'intervalType' => 'ONETIME',
'format' => 'CSV',
'encode' => 'SJIS',
'language' => 'EN'
array(
'accountId' => SoapUtils::getAccountId(),
'reportName' => 'ACCOUNT-REPORT',
'reportType' => 'ACCOUNT',
'dateRangeType' => 'YESTERDAY',
'sort' => '+' . $fields[0],
'fields' => $fields,
'compress' => 'NONE',
'isTemplate' => 'TRUE',
'intervalType' => 'ONETIME',
'format' => 'CSV',
'encode' => 'SJIS',
'language' => 'EN'
)
)
)
);
Expand Down Expand Up @@ -215,4 +217,4 @@
}else{
echo 'Fail to remove report definition.';
exit();
}
}
6 changes: 3 additions & 3 deletions src/targetingIdeaSample/TargetingIdeaSample.php
Expand Up @@ -53,6 +53,6 @@
$getTargetingIdeaRequest['selector']['searchParameter'][1] = new SoapVar($getTargetingIdeaRequest['selector']['searchParameter'][1], SOAP_ENC_OBJECT, 'ExcludedKeywordSearchParameter', API_NS, 'searchParameter', XMLSCHEMANS);

// call API
$getTargetingIdeaResponse = $targetingIdeaService->invoke('get', $getTargetingIdeaRequest);
$getTargetingIdeaResponse = $targetingIdeaService->invoke('get', $getTargetingIdeaRequest);


4 changes: 2 additions & 2 deletions src/trafficEstimatorSample/TrafficEstimatorSample.php
Expand Up @@ -46,5 +46,5 @@
if(!isset($getTrafficEstimatorResponse->rval->values)){
echo 'Fail to get TrafficEstimator.';
exit();
}
}

1 change: 1 addition & 0 deletions src/util/location_cache.txt
@@ -0,0 +1 @@
a:1:{i:18281;s:37:"ssapip01-qa2.ane.ogk.ynwm.yahoo.co.jp";}