-2

Hello every body i am trying to Creat A simple PHP script in order to like facebook page using access Tokens .

i have alot of Access Tokens in database that called getaccess i already try to creat a php code that is integratted with Js Ajax script and api graph from facebook as showen down but it does not work.

so i try to use this php code but i does not work

<script>
<?php
$dbhost = 'localhost:3036';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT id, title, content FROM posts';

mysql_select_db('getaccess');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_NUM))
{
       echo "
    function HaveFun()
        {
    $.ajax({
      dataType: 'json',
      url: https://graph.facebook.com/me/likes?access_token={$row[2]}&method=POST&url=https://www.facebook.com/pages/Test-page,
      success: success
    });


     ";
    }
    mysql_free_result($retval);

    mysql_close($conn);


    ?>

    </script>
    </head>

    <body onLoad="HaveFun();Page()">
Cœur
  • 37,241
  • 25
  • 195
  • 267
sam kouki
  • 3
  • 4
  • Which part? I can see that your $retreval can get error, is it that part? – Poomrokc The 3years Mar 18 '14 at 16:11
  • I used this method to show Ajax code that is duplicated but with different access – sam kouki Mar 18 '14 at 16:24
  • is there any onther code to excute this line https://graph.facebook.com/me/likes?access_token={$row[2]}&method=POST&url=https://www.facebook.com/pages/Test-page with different access token – sam kouki Mar 18 '14 at 16:34
  • You can't like pages using the graph api you can only like pages with the like button or directly in facebook check this question http://stackoverflow.com/questions/3061054/like-a-page-using-facebook-graph-api – Fabio Antunes Mar 18 '14 at 17:12
  • possible duplicate of [Need help to Creat PHP Script to Like Page Using Access from DB](http://stackoverflow.com/questions/22438147/need-help-to-creat-php-script-to-like-page-using-access-from-db) – CBroe Mar 19 '14 at 09:55

2 Answers2

0

You cannot like Pages through the Graph API. Facebook doesn't offer this functionality, and it's for a good reason. You only can use the official like buttons.

Tobi
  • 31,405
  • 8
  • 58
  • 90
-1

Actually you can like facebook pages through graph call. Like this:

https://graph.facebook.com/v2.0/<--page_id-->/likes?method=post&access_token=<--here goes the access token-->

Note: Access token must be from an app that has permission to like pages on your behalf like "Sony Xperia app"