Mikael Lemberg
Mikael Lemberg

Reputation: 11

Open Graph cURL command line --> php?

I am going nuts about this. I need the following cURL command line as a PHP script, that automatically triggers a "read" action when a user visits a certain page:

curl -F 'access_token=XXXXXXXXX' \
     -F 'article=<?php the_permalink(); ?>' \
        'https://graph.facebook.com/me/lemberg_dk:read'

I have spent the last 24 hours researching cURL and trying to understand how to convert it to PHP, but I simply just can't grasp it.

Can anybody here help me?

Upvotes: 1

Views: 1774

Answers (1)

zysoft
zysoft

Reputation: 2358

Try this:

$ch = curl_init('https://graph.facebook.com/me/lemberg_dk:read');
curl_setopt_array($ch, array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => array(
        'access_token' => 'XXXXXXXXX',
        'article' => the_permalink()
    )
));
$response = curl_exec($ch);
curl_close($ch);

After execution you will get server response in $response variable.

Of course to make it to work you will need cURL extension loaded.

Upvotes: 1

Related Questions