简体   繁体   中英

Retrieve a Get Http request in php

I need to retrieve a get http request in php and store it in a variable.

I need to execute the following:

https://graph.facebook.com/oauth/access_token?
     client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&
     grant_type=client_credentials

I know this is simple. just not able to get my head around it.

$content = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=client_credentials');

Within the Open Graph protocol page on Facebook, there is an example within the documentation coded using PHP: http://developers.facebook.com/docs/opengraph/

<?php

$ogurl = "INSERT_YOUR_OG_URL_HERE";
define(FACEBOOK_APP_ID, "YOUR_APP_ID_HERE");
define(FACEBOOK_SECRET, "YOUR_SECRET_KEY_HERE");

$mymessage = "Hello World!";

$access_token_url = "https://graph.facebook.com/oauth/access_token"; 
$parameters = "grant_type=client_credentials&client_id=" . FACEBOOK_APP_ID ."&client_secret=" . FACEBOOK_SECRET;
$access_token = file_get_contents($access_token_url . "?" . $parameters);

$apprequest_url = "https://graph.facebook.com/feed";
$parameters = "?" . $access_token . "&message=" . urlencode($mymessage) . "&id=" . $ogurl . "&method=post";
$myurl = $apprequest_url . $parameters;

$result = file_get_contents($myurl);

// output the post id
echo "post_id" . $result;
}
?>

The key line in actually making the call being:

$result = file_get_contents($myurl);

There is also a good amount of other information about the resulting object you get back there that would be good to take a look into.

Hope this is helpful.

if ($fp = fopen('https://graph.facebook.com/oauth/access_token?
 client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&
 grant_type=client_credentials', 'r')) {
   $content = '';
   // keep reading until there's nothing left 
   while ($line = fread($fp, 1024)) {
      $content .= $line;
   }

   // do something with the content here
   // ... 
} else {
   // an error occured when trying to open the specified url 
}

You mean something like

$client_id = $_GET['client_id'];
$client_secret = $_GET['client_secret'];
$grant_type = $_GET['grant_type'];

?

Or rather something like

$content = file_get_contents($url);

?

Use the following

$id = $_GET['client_id'];
$type = $_GET['grant_type'];
$secret = $_GET['client_secret'];

Hope this helps you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM