I'm stuck on a project. I want to update a column in Google Sheets using PHP but I'm unable to figure it out.
Here is my code:
<?php
$url = 'https://sheets.googleapis.com/v4/spreadsheets/1MWmhO8PyjwxgeELR-NZg4Y9WhhGwaf6Wt-hD7gtadcg/values/AppList!$A:$H?key=AIzaSyDdkIF9YlaAvgIqv66sA2Hci4LZSrmGjLM';
$json = json_decode(file_get_contents($url));
$rows = $json->values;
foreach($rows as $row) {
var_dump($row);
}
?>
With this code, I'm able to fetch the data from Google Sheets to PHP but I don't know how to update from PHP to Google Sheets column Status.
Related
So, currently i am using firebase for storing my app data online,
I would like to create my own database,
so i was planning to get a 100gb bandwidth hosting plan with php and mysql (is that bandwidth enought) per download, my app downloads approximately 0.4MB of data (as per firebase).
So, to create the api, i just have to encode the mysql data into json and print it ? then my android app will read it and use it ? is this the best method ?
$sth = mysqli_query("SELECT ...");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
or is there any other, more efficient method to do this ?
Yes but you should send response code like 200,403 as well.
here is a similar question
How to write a REST API?
I'm attempting to load the contents of a single cell of Google Sheet into a PHP variable. From there I intend to make an image change on a website when the cell contents are changed to different values. I can't get the cell contents to load into a PHP variable to get this ball rolling though.
Google Sheets API gives the following PHP code to do this:
$result = $service->spreadsheets_values->get($spreadsheetId, $range);
When I use this code after substituting my spreadsheetId and range, I echo $result and get nothing. I'm sure thre's something I'm missing in the code or that the variables $result or $service need to be defined, but Google dropped the ball on the PHP side aparently. Any help would be appreciated.
download the V1 master (not master) from:
https://github.com/google/google-api-php-client-services/issues?utf8=%E2%9C%93&q=spreadsheets_values
copy on server, verify path of requires
put your code in an exemple, with the class declared for $service and variables $range, $spreadsheetId and $api_key (from explorer api of google, to auhenticate:
https://console.developers.google.com/apis/credentials
)
run the modified exemple
PS: I look for multi-range in case you find the method with :
$range[]= 'Sheet1!A:C'; // I try to have all sheets in once
$response = $service->spreadsheets_values->get($spreadsheetId, $range);
$values = $response->getValues();
I'm working on a website that stores information in databases using mysql. I want to display that information using interactive diagrams via google charts. The problem is that I cant figure out how to use the mysql data with google charts. I did some research and found that I need to encode the data in JSON format but I'm not sure as to how I can do that. Any help would be greatly appreciated.
Thanks.
(one method - there are probably many)
Use php to create the JSON strings from your query and pass these to google charts on the client.
(pcode)
<?php
$rows = PDO->query( "select col0, col1 from table" );
echo "jsonvar = {";
foreach( $rows as $row )
{
echo "{" . $row->col0 . "," . $row->col1 . "},";
}
echo "};";
?>
// some call to google charts on the client
gchart.make_a_cool_graph( jsonvar, otherparams,... );
I'm trying to read data from a Google Spreadsheet using the PHP Google Spreadsheet Client (https://github.com/asimlqt/php-google-spreadsheet-client). After much hairpulling, I've got the auth working; I can add rows to the spreadsheet; using CellFeed I can pull individual cell data properly... but the one that's eluding me is using the ListFeed to pull data from rows.
It DOES appear to be working, however, it's only pulling data from the first row. Exporting the result with print_r shows that it IS pulling all of the rows, however, it's not breaking the data out into the array. I've been through the source for the client and I can't see anything wrong in there, either. Sigh.
I've tried it with different worksheets in the same spreadsheet, as well as with a different spreadsheet, just to make sure that it's not something with the data that's preventing it from working properly.
Here's what I've got:
$serviceRequest = new Google\Spreadsheet\DefaultServiceRequest($accessToken);
Google\Spreadsheet\ServiceRequestFactory::setInstance($serviceRequest);
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
$spreadsheet = $spreadsheetFeed->getByTitle('Prime Pubs Test Datasheet');
$worksheetFeed = $spreadsheet->getWorksheets();
$worksheet = $worksheetFeed->getByTitle('Configuration');
$listFeed = $worksheet->getListFeed();
foreach ( $listFeed->getEntries() as $entry ) {
print_r($entry->getValues());
}
Like I said, it will dump out the first row, but nothing else.
Here's a snippit of the worksheet... nothing out of the ordinary: http://imgur.com/AIax8tf
Thanks.
... Yeah. Apparently it doesn't like blank lines in the spreadsheet. It thinks the sheet is done after that, so it doesn't process any further.
My goal is to use a playlist ID to get the video ID of each video within that playlist.
I'm having trouble figuring out YouTube's API (I'm a relatively new programmer).
Basically, I want to:
Send an XML request to http://gdata.youtube.com/feeds/api/playlists/ID_OF_PLAYLIST
Using the response (which is the part I don't understand how to navigate), append all the video IDs to an array.
Seems pretty straightforward. I've been grabbing the information from YouTube using simplexml_load_file($url); in case that is important.
Thanks for the help!
Here you go, I made an example:
<?php
$data = file_get_contents('http://gdata.youtube.com/feeds/api/playlists/PL4BC045240D2FB11B/?v=2&alt=json&feature=plcp');
if (!$data)
throw new Exception("Data retrieval failed.");
$dataAsArray = json_decode($data);
$feed = $dataAsArray->feed->entry;
$videoID_array = array();
if(count($feed))
{
foreach($feed as $item)
array_push($videoID_array, $item->{'media$group'}->{'yt$videoid'}->{'$t'});
}
print_r($videoID_array);
?>
Where PL4BC045240D2FB11B of course is the Playlist ID!
Example PHPFiddle