php - how to post data from custom text box into facebook user timeline -


this code works if pass data variable directly, want data user input field,

$data = ["message" => "testing post"];

$profile_request = $fb->post('/me/feed', $data);

the above code work, if post method not working suggestion appreciate,

index.php      <?php         require_once 'appconfig.php';         $permissions = ['email','publish_actions'];         $loginurl = $helper->getloginurl('http://localhost/api-integeration/fbpost/logged.php', $permissions);         //echo '<a href="' . $loginurl . '">post facebook!</a>';         ?>          <!doctype html>         <html>         <head>             <title>post user timeline</title>         </head>         <body>             <form action="<?php echo $loginurl; ?>" method="post" accept-charset="utf-8">                 <textarea rows="6" name="message" style="width:40%;" placeholder="enter post data"></textarea>                 <br />                 <input type="submit" value="post facebook" name="submit">             </form>         </body>         </html>  logged.php  <?php   require_once 'appconfig.php';  try {     if (isset($_session['facebook_access_token'])) {         $accesstoken = $_session['facebook_access_token'];     } else {         $accesstoken = $helper->getaccesstoken();     } } catch(facebook\exceptions\facebookresponseexception $e) {     // when graph returns error     echo 'graph returned error: ' . $e->getmessage();      exit; } catch(facebook\exceptions\facebooksdkexception $e) {     // when validation fails or other local issues     echo 'facebook sdk returned error: ' . $e->getmessage();     exit;  }  if (isset($accesstoken)) {     if (isset($_session['facebook_access_token'])) {         $fb->setdefaultaccesstoken($_session['facebook_access_token']);     } else {         // getting short-lived access token         $_session['facebook_access_token'] = (string) $accesstoken;          // oauth 2.0 client handler         $oauth2client = $fb->getoauth2client();          // exchanges short-lived access token long-lived 1         $longlivedaccesstoken = $oauth2client->getlonglivedaccesstoken($_session['facebook_access_token']);          $_session['facebook_access_token'] = (string) $longlivedaccesstoken;          // setting default access token used in script         $fb->setdefaultaccesstoken($_session['facebook_access_token']);     }      // redirect user same page if has "code" variable     if (isset($_get['code'])) {         header('location: logged.php');     }      /*user messaegs*/      $usermsg = $_post['message'];      $data = ["message" => $usermsg];      try {         $profile_request = $fb->post('/me/feed', $data);         $user = $profile_request->getgraphuser();     } catch(facebook\exceptions\facebookresponseexception $e) {         // when graph returns error         echo 'graph returned error: ' . $e->getmessage();         session_destroy();         // redirecting user app login page         header('location: ./');         exit;     } catch(facebook\exceptions\facebooksdkexception $e) {         // when validation fails or other local issues         echo 'facebook sdk returned error: ' . $e->getmessage();         exit;     }      // can redirect page , use access token $_session['facebook_access_token'] } else{     print_r($_post);     echo "not set"; }  ?> 


Comments