Can anyone help me to solve this issue, I am breaking my head for the past 48 hours on this.
Objective: I am trying to post some information to my friends facebook wall through my website. Everything was working fine before but I am getting an error now:
Fatal error: Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action thrown in /home/abcd/public_html/front_apps/controllers/src/base_facebook.php on line 1039
Also what I am trying to do is, to post it on my friends Facebook wall when I am offline, using cron
and to post daily by 12.00 am.
I am using PHP code here is the code:
<?php
$message = "Message goes here";
$link = "http://link.com/";
$picture = "http://link.com/1.jpg";
$sendTo = "my friend id";
$access_token = "access tocken";
require 'src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'appId',
'secret' => 'secret_ID',
)); <br>
$attachment = array('message' => $message, 'link' => $link, 'picture' => $picture );
$api = "/$sendTo/feed/?access_token='.$access_token,";
$result = $facebook->api($api,'post', $attachment);
?>
Since facebook deprecated Offline Acces, you have to get long lived token (valid for 60 days) and store it on your server! Here is what I'm using.
To Get the long lived token right away use server side login flow
$code = $_REQUEST["code"];
//get acces token from user
$token_url = "https://graph.facebook.com/oauth/access_token?"."client_id=".$config[‘appId’]."&redirect_uri=".urlencode($my_url)."&client_secret=".$config[‘secret’]."&code=".$code;
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$token = $params['access_token']; //long live the token
and for posting to users wall
//construct the image URL
$url ="https://".$_SERVER['SERVER_NAME'].$event_data['path'];
$img_url = urlencode($url); //encode the URL
$text= urlencode($event_data['text']);
//post to user wall - picture and text
$post_url= "https://graph.facebook.com/".$user_data['uid']."/photos?url=".$img_url."&message=".$text."&access_token=".$user_data['token']."&method=post";
$upload_photo = file_get_contents($post_url);
Hope it helps ;)
Check out this link and follow the steps.
http://eagerfish.eu/using-facebook-off-line-access-to-post-on-users-wall/enter link description here
Check the below link also,
Uncaught OAuthException: (#200), when trying to post on wallenter link description here