views:

112

answers:

2

I am trying to use facebook Graph API, to update a users staus message.

I am getting the following error while using it, I think the new graph sdk is not being properly referenced ?

Notice: Undefined property: Facebook::$api_client in /users/home/aafhe7vh/web/public/update.php  on line 9

Fatal error: Call to a member function users_hasAppPermission() on a non-object in /users/home/aafhe7vh/web/public/update.php on line 9

This is the file I am using http://github.com/facebook/php-sdk/blob/master/src/facebook.php

Following is the content of my update.php:


# <?php  

  include_once ('facebook.php');
  $api_key = '@@@@@@@@@@@@@@@@@@@2';
  $secret  = '$$$$$$$$$$$$$$$$$$$$44';
  global $facebook;
  $facebook = new Facebook($api_key, $secret);

# include_once("config.php");  
# if (!$facebook->api_client->users_hasAppPermission("status_update")){  
# echo '<fb:prompt-permission perms="status_update" next_fbjs="greet()">Let us update your status </fb:prompt-permission>';  
# $visibility = "none";  
# }  
# else  
# $visibility = "block";  
#   
# if(isset($_POST['hello']))  
# {  
#     $facebook->api_client->users_setStatus($_POST['hello']);  
#     echo "<p>Your status has been updated</p>";  
# }  
# ?>  
# <div id="statusdiv" style="display:<?=$visibility;?>;">  
#     <form method="POST">  
#         Please update your status:<br/>  
#         <input type="text" name="status" /> <br/>  
#         <input type="submit" value="change status" />  
#     </form>  
# </div>  
#   
# <script>  
# 
function greet()  
# {  
#     var session = "<?=$facebook->api_client->session_key;?>";  
#     document.getElementById("statusdiv").setStyle("display","block");  
#     new Dialog().showMessage("Info","Thank you for granting us this permission! ");  
# }  
</script>

I used the above code from here , http://fbcookbook.ofhas.in/tag/extended-permission/

I am not sure what the config.php should contain so I have removed that line in my code.

Thanks.

A: 

With the Graph API, when the user allows your application, you must say that "I need status_update".

Andrew
sorry , didn't get you. Are you referring to "Let us update your status" statement in my code? I am just trying this out as an example so haven't yet put proper messages for the user.
p1
As in "when I authorize this application I'd like the status_update permission"
Andrew
+1  A: 

You're including newest PHP SDK but your code is written for the old SDK. So, either downgrade to the previous version of the SDK, or change your implementation.

// Old SDK
$facebook->api_client->users_setStatus($_POST['hello']);  

// New SDK
$facebook->api ( array(
    'method' => 'users.setStatus'
  , 'status' => $_POST['hello']
  , 'uid'    => /* user's facebook id */
) );

See the corresponding documentation for more details about the parameters.

EDIT

A response to your questions

1] When using the new SDK - everything is different. You have to create the object like this

$facebook   = new Facebook(array(
    'appId'  => 'FB_APP_ID'
  , 'secret' => 'FB_APP_SECRET'
  , 'cookie' => true
));

2] Fixed my code above

3] http://developers.facebook.com/docs/reference/api/

Peter Bailey
thanks Peter, I decided to use the new SDK to save trouble in future.1] When I use the code you gave, I get "101 The API key submitted is not associated with any known application" Thats because my application is not published yet!!. So there is no way I can test it?2] Also, is there a way I can give a userid or something in the above API to indicate which user's status I want to update. 3] Where can I find the method signatures of the new API's ?
p1
Updated with new info
Peter Bailey
Thanks Peter for the updates, I think new API documentation is really frustrating. I dont see API signatures anywhere on that page. Now I get "102: parameters uid or session key required" error and offcourse $facebook = $facebook->require_login() wont work any more. Shld I use the authentication mentioned here http://developers.facebook.com/docs/api#authorization .Infact I want to post to user's status even if he is not logged in, basically that was the point of extended permissions . Any suggestions Peter? Should I do well just by goin to old API, can I still use extended permissions there ?
p1
Finally I moved on to the old APIs and got it working.I used $uid = $facebook->require_login($required_permissions = 'email,status_update,offline_access');and then $facebook->api_client->users_setStatus("hello",$uid);;This works fine for me !!
p1
However,now this works only if I have post by getting a uid $facebook->require_login .However if I hard code the value of uid and then use $facebook->api_client->users_setStatus("hello",$uid);I get :Fatal error: Uncaught exception 'FacebookRestClientException' with message 'An unknown error occurred' in /PATH/facebookapi_php5_restlib.php(1813): FacebookRestClient->call_method('facebook.users....', Array) #1 /PATH/file.php(9): FacebookRestClient->users_setStatus('hello', '1000247983459873') #2 {main} thrown in /PATH/facebookapi_php5_restlib.php on line 3065
p1
following are the lines corresp to line 3065:if (is_array($result) 3067 }
p1
You should probably start a new topic for this
Peter Bailey
okay .. thnx for your help .. I marked your reply to this question as accepted answer :)
p1

related questions