Question

I am trying to post a picture on facebook by the graph API ,How ever I am unable to post that. I get this error

Array ( [error] => Array ( [message] => (#100) Invalid parameter [type] => OAuthException [code] => 100 ) )

Here is my Code

$sqls= mysql_query($sql);
    while($sqlr = mysql_fetch_array( $sqls, MYSQL_NUM ))
 {
     $users[]= $sqlr['regidfriendsid'];
 }

 for ($t=0 ; $t<3;$t++)
 {

$tag[$t] = array( 'tag_uid' => ($users[$t]), 'x' => (20+$x), 'y' => (85+$y) );

$x=$x+200;
$z++;
        if ($z%4==0)
        {
        $y=$y+178;
        $x=0;

        }
 }

$tag = array($tag[1], $tag[2], $tag[3]);    

$tags = json_encode($tag);
print_r($tags);
// end loop for tags


//upload photo
$file= 'styleimage/save_as_this_name.jpg';
$args = array(
   'message' => 'My Stylish friends',
    'tags' => $tags, 
);
print_r($args);
$args[basename($file)] = '@' . realpath($file);
$ch = curl_init();
$url = 'https://graph.facebook.com/me/photos?access_token='.$_SESSION['access_token'];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
//returns the photo id
print_r(json_decode($data,true));

OUTPUT

        [{"tag_uid":"100003656759153","x":220,"y":85},{"tag_uid":"100004078326378","x":420,"y":85},{"tag_uid":"100000034798548","x":620,"y":85}]@@@@@Array ( [message] => My Stylish friends [tags] => [{"tag_uid":"100003656759153","x":220,"y":85},{"tag_uid":"100004078326378","x":420,"y":85},{"tag_uid":"100000034798548","x":620,"y":85}] ) 

--Before posting the actual content of tags . Now trying to post ---

    Array ( [error] => Array ( [message] => (#100) Invalid parameter [type] => OAuthException [code] => 100 ) )
Was it helpful?

Solution

The problem is x,y coordinate where you want to add tags.

x and y should be as a percentage offset from the left ( for x ) / top ( for y ) edge of the picture i.e.

x and y should be in between 0 - 100.

Facebook Documentation

You can use rand() function

x = rand ( 0, 100 );
y = rand ( 0, 100 );

May be this will help you out. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top