GoogleAppsでZendFrameworkを使用した2-legged OAuth

分かりにくかったので、メモ

■サンプル
(ZendFramework 1.11.11を使用)

<?php

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Docs');
Zend_Loader::loadClass('Zend_Gdata_Spreadsheets');
Zend_Loader::loadClass('Zend_Oauth_Token_Access');
Zend_Loader::loadClass('Zend_Oauth_Consumer');

// 2-legged oauth
$config = array(
	'requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER,
	'version' => '1.0',
	'signatureMethod' => 'HMAC-SHA1',
	'consumerKey' => "yourdomain.com",
	"consumerSecret" => "xxxxxxxxxxxxxxxxxxxx"	// ※ドメインの秘密キー
);

$token = new Zend_Oauth_Token_Access();
$httpClient = $token->getHttpClient($config);

// Spreadシートの場合
$service = new Zend_Gdata_Spreadsheets($httpClient);

$spreadsheetKey = "xxxxxxxxxxxxxxxxxxxxxxx";
$sheet_id = "odx";

	$query = new Zend_Gdata_Spreadsheets_ListQuery();
	$query->setSpreadsheetKey($spreadsheetKey);
	$query->setWorksheetId($sheet_id);

	// ※この処理を追加する
	$account = "you@yourdomain.com";
	$query->setParam("xoauth_requestor_id", $account);

	
	$listFeed = $service->getListFeed($query);

	$list = array();
	$rows = $listFeed->entries;
	foreach ($rows as $row) {
		// 行データ
		$rowData = $row->getCustom();
	}

?>
The following two tabs change content below.

taira

Sofrware Engineer.

Comments are closed.