Google Spreadsheet API via PHP - php

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

Related

How to use Noembed for link preview in PHP

I found noembed as a free alternative of embed.ly
But There is no DOCS for using its service.
Can anyone help me to use NoEmbed in PHP and getting the Thumb Link back from JSON return?
(I think This can be solved using CURL, but as I don't know too much about CURL, I am looking at you, No Curl:preferred)
file_get_contents() is what you are looking for.
This sample should be self-explanatory.
$json = file_get_contents('http://noembed.com/embed?url=http%3A//www.youtube.com/watch%3Fv%3DbDOYN-6gdRE');
var_dump(json_decode($json)->thumbnail_url);

Get Message in PHP

I'm trying very simple in PHP and not very sure what to search here or on google.
Problem is -
In PHP function I want to call/get a URL
http://www.example.com/message?Name=MyNameIsX
and like to read the return value (body) at this URL (which may contain "Your Name is MyNameIsX")
I tried
$data = file_get_contents($url)
This is timing out; although I'm able to open the $url in the browser.
Yes, file_get_contents normal use for files on this server and base on support and setting this perhaps is not allow.
See PHP CUrl http://php.net/manual/en/curl.examples.php or example
http://php.net/manual/en/curl.examples.php, http://php.net/manual/en/curl.examples-basic.php
You could use cUrl as suggested by FIG-GHD742 but I find the HTTP extension a lot easier to use. It's newer and has a neat OOP api.
Another method is that you can actually do an include/require with these, but it's generally a bad idea to do so if you don't control the source from which the data is coming
It sounds like you need to enable loopback calls on the server (self-calls). It would be better to get the data on the backend if you need it on the same server. Via a PHP API or calls to a database.
**
This will help you lot : http://php.net/manual/en/curl.examples.php
http://php.net/manual/en/curl.examples.php,
http://php.net/manual/en/curl.examples-basic.php
**
Yes the above answers is right. some hosting providers disable it for security purpose. You may also try fopen(php) if you are not looking for Curl way. Read documentation here http://php.net/manual/en/function.fopen.php

How to request this URL and real the content of response using PHP?

I want to request this URL translate.google.com/translate_a/t?client=t&text=hello&hl=en&sl=en&tl=ar&multires=1&oc=3&prev=btn&ssel=0&tsel=0&sc=1
using PHP and reading the response. How ?
There are a number of options with cURL and readfile being the obvious ones.
You can use the file_get_contents() see http://php.net/manual/en/function.file-get-contents.php
But it is not as efficient as other methods to read remote files.
ie)
$mytranslation = file_get_contents("translate.google.com/translate_a/t?client=t&text=hello&hl=en&sl=en&tl=ar&multires=1&oc=3&prev=btn&ssel=0&tsel=0&sc=1");
Use the Google Translate API instead of requesting an HTML page and parsing the HTML.
Sample:
GET https://www.googleapis.com/language/translate/v2?key=YOUR-API-KEY&source=en&target=de&q=Your%20text

execute some function in some php file on another server(apache) and get the returned value

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.

Ajax from within PHP

I know AJAX will not be what it is called, but I am looking for something similar that can be done from within PHP itself (not using javascript).
Basically, as the PHP is creating the page, I want to query an API to gather some information that will be used on the current page. Is this possible, and if so what would be the best method?
Thanks
You can use fopen or curl:
Here is an example to open a connection to twitters API, read the public timeline and output parts of it.
<?php
$fp = fopen("http://api.twitter.com/1/statuses/public_timeline.json?count=3&include_entities=false","r");
while($data = fgets($fp))
{
$json .= $data;
}
$arr = json_decode($json);
print_r($arr);
?>
You are probably wanting curl.
http://php.net/manual/en/book.curl.php
If you're talking about a remote HTTP API, you would utilize cURL at runtime. It's basically PHP's way of accessing information across domains.
The above can be a little overwhelming - check out the simple example page to get you started. If available, I suggest working with cURL from the command line, as there's quite a few options on there. It's a good way to get familiar with the command and different options available.

Categories