Blue Sky
Blue Sky

Reputation: 323

Make an API call in PHP without using Curl

I want to make the following API call in PHP:

https://www.googleapis.com/freebase/v1/search?indent=true&filter=%28any+type%3A%2Fcvg%2Fcomputer_videogame%29

How can I do so without using curl?

Upvotes: 0

Views: 874

Answers (4)

user3141031
user3141031

Reputation:

This returns json. You should use json_decode() and file_get_contents() for this.

Example:

<?php

$file = file_get_contents("https://www.googleapis.com/freebase/v1/search?indent=true&filter=%28any+type%3A%2Fcvg%2Fcomputer_videogame%29");

$json = json_decode($file, true);

echo "<pre>";
print_r($json);
echo "</pre>";

?>

Upvotes: 1

David Ansermot
David Ansermot

Reputation: 6112

Use "file_get_contents" with the right configuration.

http://fr.php.net/file_get_contents

Upvotes: 0

Calimero
Calimero

Reputation: 4288

If it's a simple GET request, file_get_contents can do that reasonably well :

$return = file_get_contents('https://www.googleapis.com/freebase/v1/search?indent=true&filter=%28any+type%3A%2Fcvg%2Fcomputer_videogame%29');

Provided you can process the return body (depends on content-type), and do not need to process errors/special http headers/authentication.

Upvotes: 0

Fabien Warniez
Fabien Warniez

Reputation: 2741

Use the PHP method: file_get_contents(): https://www.php.net/file_get_contents

Upvotes: 1

Related Questions