Last active
November 5, 2015 18:59
-
-
Save sakadon/b251728d4aa963d0c690 to your computer and use it in GitHub Desktop.
Google SpreadSheetsをGoogle APIs Client Library for PHP 1.1.6で叩くための準備 ref: http://qiita.com/sakadon/items/84593201b8801a8a3a8a
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"private_key_id": "################", | |
"private_key": "-----BEGIN PRIVATE KEY-----\#####################################################################################################-----END PRIVATE KEY-----\n", | |
"client_email": "########@developer.gserviceaccount.com", | |
"client_id": "#########gsa.apps.googleusercontent.com", | |
"type": "service_account" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// load Google APIs Client Library for PHP ver 1.1.6 | |
require_once "/unko/Google/autoload.php"; | |
$client = new Google_Client(); | |
$client->setApplicationName("getSpreadsheet"); | |
$credentials = $client->loadServiceAccountJson("/unko/.secret/certkey.json", array( | |
Google_Service_Drive::DRIVE | |
)); | |
$client->setAssertionCredentials($credentials); | |
$client->getAuth()->refreshTokenWithAssertion(); | |
$accessTokenJson = $client->getAccessToken(); | |
$accessToken = json_decode($accessTokenJson)->access_token; | |
// GET spreadsheets | |
$sheet_id = "##########################################"; | |
$request = new Google_Http_Request( | |
"https://spreadsheets.google.com/feeds/worksheets/{$sheet_id}/private/full?alt=json", | |
"GET", | |
array("Authorization" => "Bearer {$accessToken}") | |
); | |
$curl = new Google_IO_Curl($client); | |
$res = $curl->executeRequest($request); | |
// データ | |
$data = json_decode($res[0]); | |
//print_r( $data['feed']['entry'] ) | |
foreach ($data->feed->entry as $sheets) { | |
if( $sheets->title->{"\$t"} == 'シート名は直接指定' ) { | |
foreach ($sheets->link as $links) { | |
if( $links->rel == 'http://schemas.google.com/spreadsheets/2006#listfeed' ){ | |
$listfeed = $links->href; | |
echo '$listfeed: '.$listfeed; | |
} | |
if( $links->rel == 'http://schemas.google.com/spreadsheets/2006#cellsfeed' ){ | |
$cellsfeed = $links->href; | |
echo '$cellsfeed: '.$cellsfeed; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment