K
K
krasulya2011-05-24 23:10:52
PHP
krasulya, 2011-05-24 23:10:52

Facebook Graph API

The customer asks to link his Facebook account to the site so that all changes on the site are noted on Facebook on the wall.

Tried using their API. The code is this: I get $access_token like this: I.e. I am logged in to facebook with a customer account. I ran the script and got $access_token. Then, copying it manually, I inserted it into the script for making an entry on the wall on Facebook. But the action of $access_token is about 2 hours. After that, you need to get a new one. The option with authorization through Facebook does not roll, because. There are many different users on the site. Is it possible to somehow make a request through the Graph API using the login\password connection somehow? Or how else to solve this problem?

$post_data = array(
'access_token' => $access,
'link' => 'http://parademodels.com/Niclette',
'picture' => 'http://www.parademodels.com/public/avatars/Niclette/small.jpg',
'name' => 'Niclette at parademodels',
'caption' => 'Some caption text for testing...',
'description' => 'And this is much bigger text then caption. Here I can use several sentenses, but I won\'t'
);

echo '

';
  var_dump($post_data);
  echo '
';

$ch = curl_init('https://graph.facebook.com/149879695076646/feed');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$res = json_decode(curl_exec($ch));



$code = $_GET['code'];

$app_id = {id_приложения};
$app_secret = {секретный_ключ};
$my_url = {url};

if (empty($code)) {

$dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" . $app_id;
$dialog_url .= "&redirect_uri=" . urlencode($my_url);
$dialog_url .= "&scope=email,publish_stream";
header("Location: " . $dialog_url);

} else {
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=" . $app_id
. "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code;

parse_str(file_get_contents($token_url), $parsed);
}




Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sajgak, 2011-05-24
@sajgak

You need to ask the user for offline access, then the token will be valid forever

D
dmomen, 2011-05-24
@dmomen

You need to use the offline_access permission. Set via a parameter in the OAuth query string: scope=offline_access.

K
krasulya, 2011-05-25
@krasulya

Thank you!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question