html - PHP Facebook request permissions publish -
when log in on facebook requires me permits. here code use log in , requires permits:
<?php session_start(); // added in v4.0.0 require_once 'autoload.php'; require 'functions.php'; use facebook\facebooksession; use facebook\facebookredirectloginhelper; use facebook\facebookrequest; use facebook\facebookresponse; use facebook\facebooksdkexception; use facebook\facebookrequestexception; use facebook\facebookauthorizationexception; use facebook\graphobject; use facebook\entities\accesstoken; use facebook\httpclients\facebookcurlhttpclient; use facebook\httpclients\facebookhttpable; // init app app id , secret facebooksession::setdefaultapplication( '*************','*************************' ); $required_scope = 'public_profile, publish_actions, email, manage_pages'; //permissions required // login helper redirect_uri $helper = new facebookredirectloginhelper('http://www.bestparty.altervista.org/app/facebook/fbconfig.php' ); try { $session = $helper->getsessionfromredirect(); } catch( facebookrequestexception $ex ) { // when facebook returns error } catch( exception $ex ) { // when validation fails or other local issues } // see if have session if ( isset( $session ) ) { // graph api request user data $request = new facebookrequest( $session, 'get', '/me?$fields=access_token' ); $response = $request->execute(); // response $graphobject = $response->getgraphobject(); $fbid = $graphobject->getproperty('id'); // facebook id $fbfullname = $graphobject->getproperty('name'); // facebook full name $femail = $graphobject->getproperty('email'); /* ---- session variables -----*/ $_session['fbid'] = $fbid; $_session['fullname'] = $fbfullname; $_session['email'] = $femail; checkuser($fbid,$fbfullname,$femail); /* ---- header location after session ----*/ $cookie_name = 'fbid'; $cookie_value = $fbid; setcookie($cookie_name, $cookie_value, time() + (86400 * 30), '/'); $cookie_name2 = 'fullname'; $cookie_value2 = $fbfullname; setcookie($cookie_name2, $cookie_value2, time() + (86400 * 30), '/'); header("location: ../gestaccount.php"); } else { $cookie_name = 'fbid'; $cookie_value = $fbid; setcookie($cookie_name, $cookie_value, time() + (86400 * 30), '/'); $loginurl = $helper->getloginurl( array( 'scope' => $required_scope ) ); header("location: ".$loginurl); } ?>
when try publish post, doesn't work. , gives me error:
fatal error: call member function api() on non-object in /membri/bestparty/app/try.php on line 11
this code use publish post:
<?php require_once 'facebook/autoload.php'; $params = array( 'message' => "your message", 'name' => "hello world", 'description' => "hello world", 'link' => "hello world", 'picture' => "hello world", ); $post = $facebook->api("/$user/feed","post",$params); echo "lalalal"; ?>