Formatting JSON Data using PHP - php

I have the following code:
<?php
$ids = 'ids=com.hugogames.hugotrollwars';
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $ids
)
);
$context = stream_context_create($opts);
$result = file_get_contents('https://play.google.com/store/xhr/getdoc', false,
$context);
$convert = explode("\n", $result);
Basically its pulling permissions from the Playstore and displaying it as a string. The issue I am having is removing the un needed data (image links, description) and only show the permissions and the permissions description. I tried using the json_decode function with php and it returned NULL.
Is there something i'm missing?
Any help is greatly appreciated!

$result is not valid json. Google Play API is using a protobuf variant.
http://www.segmentationfault.fr/publications/reversing-google-play-and-micro-protobuf-applications/
There are also php libraries to talk to google play.
https://github.com/splitfeed/android-market-api-php
https://github.com/thetutlage/Google-Play-Store-API

Related

how to use another website to make a query with php?

I want to use sci-hub.cc to download scientific papers, but it is in russian and it is not easy to use.
It has a textfield for enter DOI or paper link.
Now, I want to make a website that, when users insert paper link, send this link to sci-hub as a query and then download it. How can I do this in php?
Thanks a lot.
i dont know how your page is working but what you looking for is a "POST" Request with.
The code below "does" the same if you type in something in the field on your page:
<php
$url = 'http://sci-hub.cc/';
$data = ['Request'=>'TEXT FOR FIELD'];
$options = array('http' => array(
'method' => 'POST',
'content' => http_build_query($data),
'header'=> "Content-Type: application/x-www-form-urlencoded \r\n")
);
$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
?>

file_get_contents() with no response - php

I am trying to call a web service which basicaly looks like this:
http://10.10.10.10:8080/gw/someAction?amount=10&description='Some description'
So this is how i call this web service:
$endpoint = "http://10.10.10.10:8080/gw/someAction?amount=10&description='Some description'";
$opts = array('http' =>
array(
'method' => 'GET',
'header' => 'Content-type: application/xml'
)
);
$context = stream_context_create( $opts );
$result = file_get_contents( $endpoint, false, $context );
$xml_result = simplexml_load_string( $result );
echo $xml_result->success;
So here, i got nothing, the xml_result is empty. And here is the interesting part - when i remove the blank space from the description:
http://10.10.10.10:8080/gw/someAction?amount=10&description='Somedescription'
Everything is just fine, I got the answer from the web service. Also tried to call the web service with the chrome rest client WITH the blank space in the description and everything is OK, i have response. So this leads me to some kind of PHP problem here with the blank spaces in the web service. Please, help !
UPDATE:
print_r($result)
results in
1
This is not a valid URL, spaces must be escaped:
http://10.10.10.10:8080/gw/someAction?amount=10&description='Some%20description'
You might want to take a look at How to properly URL encode a string in PHP?.

using a context-stream resource with file_get_contents returns a NULL string

I'm using PHP 4.3.9 and am trying to POST to a url without a form using stream_context_create like below:
function do_post_request($url, $postdata) {
$content = "";
foreach($postdata as $key => $value)
$content .= "$key=$value&";
$content = urlencode($content);
$params = array('http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded',
'content' => $content
));
$ctx = stream_context_create($params);
$result = file_get_contents($url, false, $ctx);
var_dump($result);
This code is taken almost word for word from the php manual and I've seen it in several places here on stackoverflow as well.
If I do file_get_contents without $ctx, var_dump($results) will display the $url properly (but without the necessary changes $_POST would cause, of course). With $ctx, var_dump($result) is NULL. So something is wrong with $ctx but I have no idea what. Am I setting up my $params incorrectly or something?
Any insight would be appreciated. If there is another way to pass POST data to a url I wouldn't mind hearing that either. But I cannot use cURL (or anything that needs installation) and I'm using an older version of php so my choices are limited.
Thanks

Google Spreadsheet API with PHP

I want to read from and write to Google spreadsheet using google spreadsheet API,
After long battle I was able to get access token and stored it in a session variable, but i don't understand how to exchange this token to get contents from spreadsheet and to update spreadsheet.
I was trying with below code to get a cell content. But nothing is being returned.
<?php
session_start();
$url = 'https://spreadsheets.google.com/feeds/cells/0AgxnPrGJ8****************RkMwSkZoQ2pXaFE/4/private/full/R2C2';
$headers = array(
'Authorization' => 'Bearer '.$_SESSION['access_token'],
'Gdata-version' => '3.0'
);
$postdata = http_build_query($headers);
$context =
array("http"=>
array(
"method" => "GET",
"content" => $postdata
)
);
$context = stream_context_create($context);
$ResultArray = file_get_contents($url, false, $context);
var_dump($ResultArray);
?>
See Google Spreadsheets on http://framework.zend.com/manual/1.12/en/zend.gdata.html, if you wan`t have "long battles". Your can using components of Zend Framework separately (without install full ZF).

Retrieving a PHP file using file_get_content(), cURL() or fopen() all return PHP code itself

I'm retrieving a PHP file using file_get_content(), cURL() or fopen() all return PHP code itself. It's not retrieving just the HTML code itself that PHP is outputting. How can I overcome this please?
It's basically generating an HTML newsletter preview for my customer that is generated from their CMS. However I want them to be able to copy and paste the HTML it generates into Mailchimp or such like. It just fetches the entire PHP source code though as well as the HTML :(
Hope you can help.
Thanks in anticipation.
Pete
Trying to read a local PHP file will return its source code, since its a "local" file, and is not parsed by the server.
If you wish to read the result of the PHP file you must request it from the server.
Meaning instead of doing:
$data = file_get_contents('x.php');
You should be doing
$data = file_get_contents('http://mysite.com/path/x.php');
Which will be parsed in the server, and then returned to you.
Cheers! :)
Shai.
This will work in localhost. Try this one: $url = "http://localhost/box.php";
function isAllBoxContents($boxid,$pageNum)
{
$postdata = http_build_query( array('myBoxid' => "$boxid", 'isAllBoxContents' => "all",'pageNum' => "$pageNum",'innerReq' => true ));
$opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ));
$context = stream_context_create($opts);
$url = "http://localhost/box.php";
$result = file_get_contents( $url, false, $context);
$cacheFileName = "isAllBoxContents".$boxid.$pageNum;
cacheMe($cacheFileName,$result);
}

Categories