I'm trying to read a Doc from Google with an authorized user and output the content through my page.
Everything works fine, and the output is Ok, but after few seconds, a popup window appears with an error "Google Docs has encountered an error. We are looking into the problem now. Please try one of these interim solutions: Reload this page"
My code is this:
<?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_Docs');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
Zend_Loader::loadClass('Zend_Gdata_Docs_Query');
$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$client_grabmark = Zend_Gdata_ClientLogin::getHttpClient('MYUSER#gmail.com', 'MYPASS', $service);
$service = new Zend_Gdata_Docs($client_grabmark);
$service->setMajorProtocolVersion(3);
$contentLink = 'https://docs.google.com/document/d/'DOCID'/edit';
$data = $service->get($contentLink)->getBody();
ob_start();
echo $data;
ob_flush();
exit
?>
What I'm doing wrong? If I try export to PDF everything is Ok (I just have to change the link), but I want to show the page as if I was in Google Docs.
Any help?
Best Regards
DF
You cannot output the HTML content of a Google Doc page into the context of your own page and get that to work. If you want to show a document to a user, redirect them to the Google Doc itself, using an HTTP Location header.
<?php
header("Location: $contentLink");
?>
If the user you had intended to display the doc to does not have permission to access the doc, there are two options:
Share the doc to the user using the Documents List API.
Export the document as text, HTML, or PDF using the API, and then display it to the user.
These options are detailed in the documentation.
Related
Our main goal is to upload audio references to match and automatically claim videos in Youtube. We work ok PHP.
We’re following this example:
[Uploading a new reference, so YouTube can automatically generate claims for newly uploaded videos on behalf of the asset's owner]
https://developers.google.com/youtube/partner/code_samples/php#uploading_a_new_reference__so_youtube_can_automatically_generate_claims_for_newly_uploaded_videos_on_behalf_of_the_asset_s_owner
(second half of the doc):
// Call set_include_path() as needed to point to your client library.
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';
require_once 'Google/Service/YouTubePartner.php'; // <--- This file doesn't exist!
session_start();
We got it through the old API (Google API PHP Client 0.6.7) and the "Google_YouTubePartnerService.php" file we found here: https://developers.google.com/youtube/partner/client_libraries , but this isn’t useful because we need "Service account" authentication, and the API doesn’t work with this.
So, we tried with Google API PHP Client 1.0.0 unsuccessfully. We get the authentication but we need to find this file Google/Service/YouTubePartner.php called by the example on the URL mentioned above: https://developers.google.com/youtube/partner/code_samples/php#uploading_a_new_reference__so_youtube_can_automatically_generate_claims_for_newly_uploaded_videos_on_behalf_of_the_asset_s_owner
Thanks for your help!
Looks like Content ID PHP library wasn't updated for 1.0 version on the site.
Just got it updated. Thanks for the warning. https://developers.google.com/youtube/partner/clientlib/Google-youtubePartner-v1-20140110-php-1.0.0-alpha.zip
I am trying to fetch the first images on a Facebook Page. It works on other websites - using:
$image = $doc->getElementsByTagName('img')->item(0);
But for some reason, Facebook have wrapped in the 's i need, like this:
<code class="hidden_elem" id="u_0_7"><!-- <div class="timelineLoggedOutSignUp"><div class="_5h60" id="pagelet_loggedout_sign_up" data-referrer="pagelet_loggedout_sign_up"></div></div><div class="fbTimelineTopSectionBase fbTimelineLoggedOutTopSection"><div class="_5h60" id="pagelet_above_header_timeline" data-referrer="pagelet_above_header_timeline"></div><div id="above_header_timeline_placeholder"></div><div class="fbTimelineSection mtm fbTimelineTopSection"><div id="fbProfileCover"><div class="cover" id="u_0_4"><a class="coverWrap coverImage" href="https://www.facebook.com/photo.php?fbid=632540440113248&set=a.540825239284769.1073741827.540818775952082&type=1" rel="theater" ajaxify="https://www.facebook.com/photo.php?fbid=632540440113248&set=a.540825239284769.1073741827.540818775952082&type=1&src=https%3A%2F%2Fscontent-b.xx.fbcdn.net%2Fhphotos-ash3%2F579116_632540440113248_872174037_n.png&size=851%2C315&source=10" title="Coverbillede" id="fbCoverImageContainer"><img class="coverPhotoImg photo img" src="https://scon
Note that it is wrapped into a: <!-- -->.
Is there some way I can avoid this? Maybe changing the user-agent to an older browser, where they dont use the <!-- --> wraps? I can do this, using CURLOPT_USERAGENT in my CURL settings.
Any ideas? I am quite lost here..
All of this data is available via the Facebook Graph API so you don't need to fiddle around with the DOM or scrape the page - and you don't need to be authenticated to get it. This means you don't need Facebook's SDK or need to worry about registering an application if you are just grabbing public info. Also, Facebook change their HTML all the time so scraping the content will slowly drive you mad.
A quick JS example below, this gets the cover photo for your page:
$('#GetCoverImage').click(function() {
$.getJSON(
'https://graph.facebook.com/EduKarmaDK',
function(pageData) {
console.log(pageData.cover.source);
}
);
});
Other public info about the page is available in the pageData object. Have a play around with the Graph API Explorer to see what else is available.
PHP example:
<?php
$pageData = json_decode(
file_get_contents('https://graph.facebook.com/EduKarmaDK')
);
echo($pageData->cover->source);
i want to read a google spreadsheet over google spreadsheet api via XML.
I try different ways, e.g.
<?php
$data = file_get_contents("https://spreadsheets.google.com/feeds/worksheets/WORKSHEET_KEY/private/full");
?>
or
<?php
simplexml_load_file(URL)
?>
but i only give an emtpy string.
the document is public and if i surf on the site directly, it works.
Can you help me?
Have a look at the following article: http://arlando.net/blog/connecting-to-google-spreadsheet-api-with-php/
I would also recommend reading this documentation from google API's https://developers.google.com/google-apps/spreadsheets/
This is more than likely related to the following answered question:
Loading a remote xml page with file_get_contents()
Your server probably doesn't allow opening remote urls with file_get_contents.
The accepted answer on this page shows a workaround with curl
I want to print a pdf file automatically when I click print button using php or javascript.
Thanks
You don't need to add a button. If you are loading a PDF for display on a web page by embedding it or providing a link to open in a new window, unless the document has printing disabled, the visitor can simply right-click and use the Adobe Reader print commands.
You could a message to that effect.
Attention!
Google Cloud Print is deprecated after December 2020.
I know it's not the best solution for your problem, but if your printer has native google cloudprint support or you add the printer to cloudprint via your google chrome browser you can print documents via google. Steps for adding your printer to Google Cloudprint
To print documents from PHP on Google Cloudprint you need following class php-google-cloud-print from Github.
Information about how to get the credentials is in the Readme file of the class.
With this code snippet the printing works like a charm.
require_once 'php/cprint/Config.php';
require_once 'php/cprint/GoogleCloudPrint.php';
$gcp = new GoogleCloudPrint();
$refreshTokenConfig['refresh_token'] = 'your_refresh_token';
$token = $gcp->getAccessTokenByRefreshToken($urlconfig['refreshtoken_url'],http_build_query($refreshTokenConfig));
$gcp->setAuthToken($token);
$printers = $gcp->getPrinters();
//print_r($printers); // Show available printers with IDs
if(count($printers) == 0){
exit("Could not get printers");
}else{
$printerID = "your_printer_id";
$resarray = $gcp->sendPrintToPrinter($printerID, "Document title", "path/to/document.pdf", "application/pdf");
if($resarray['status'] == true){
echo "Document has been sent to printer and should print shortly.";
}else{
echo "An error occured while printing the doc. Error code:".$resarray['errorcode']." Message:".$resarray['errormessage'];
}
}
I hope that this helps someone, because i searched desperately for an method to print from my webserver.
I want to access some function written in some php file on another server and receive the input, I have access to those server files so that I can change them for proper configuration, I have all the privilleges to do so, can anybody please guide me how can I do it, thank you
$result = file_get_contents("http://some.server/out.php");
and in this out.php
<?php
include 'some.php';
function();
I think you can implement web service or an api, and the output could be in xml or json read the content and use it on your website.
It is just Facebook graph API using URL
https://graph.facebook.com/Pepsi
The above link will fetch information regarding Facebook page of Pepsi.