create events on my Application's page
I am in a process of writing an app which works this way 1. Asks a user permission for events_create, publish_stream 2. Gets the access_token for the same 3. takes input of Title, date, time, location( ie all inputs) from a form and then calls graph api like /$app_id/events along with access token and post date
I want this to create an event within my APPLICATION's events and hence I use $app_id instead of ..../me/events
But it creates an event on USER's wall ???
I want users to be able to create an event on my wall. It should be an event whose owner is the application and the user should get invited along with his contacts( if he chooses so) ...
Basically, I think POST to /$app_id/events and /me/events work the same, I think it should not ... Am I missing something?
Thanks in advance ..
AC
HiShakyeb,
Same result ... It just creates an event in my account rather than the application's.
Here is the code I am using ..
$url = "https://graph.facebook.com/$app/events?" . $access_token;
$params = array();
// Prepare Event fields
foreach($_POST as $key=>$value)
if(strlen($value))
$params[$开发者_JS百科key] = $value;
$params['name']=mysql_real_escape_string($params['name']);
$params['description']=mysql_real_escape_string($params['description']);
$params['location']=mysql_real_escape_string($params['location']);
$params['end_time']=date('Y-m-d H:i:s', mktime(0, 0, 0, date("m") , date("d")+1, date("Y")));
$params['privacy_type']="SECRET";
// Start the Graph API call
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$result = curl_exec($ch);
$decoded = json_decode($result, true);
curl_close($ch);
I also tried just app/events? instead of $app/events?
Thanks a lot ...
Use a Page Admin access token to take an action on behalf of that application's page. To do this, get /me/accounts
with the manage_pages
permission. That will give you the pages you have access to (including the app's profile page), along with an access token to use for acting as that page/application. If you use that access token, then events will be created as the application page and not the user. See the Graph API documentation for the Page object for more details.
With PHP-SDK I uses the api call for automatic POSTING an Event in App page after filling a form.
Here the automatic process after the user (You) have an valid APP access_token and manage app/page permissions. The token to use is your APP token you receive with your FBapp connection.
Starting creating php-sdk object
$connectparam = array();
$connectparam['appId'] = 'YOURAPPID';
$connectparam['secret'] = 'YOURAPPSECRET';
$connectparam['fileUpload'] = 'true';
$connectparam['cookie'] = 'true';
$facebook = new Facebook($this->connectparam);
Building the event informations
$FBcreateAnTestEvent = array();
$nowtime = date('Y-m-d H:i:s');
$FBcreateAnTestEvent['name'] = 'Test Event in myApp from me';
$FBcreateAnTestEvent['start_time'] = $nowtime;
$FBcreateAnTestEvent['privacy_type'] = 'SECRET';
$FBcreateAnTestEvent['description'] = 'This Event is created from my WebFBApp and is a testing Event creating by Qtronik from myWebApp';
Automaticly create event
$resp = '<a href="'.$facebook->api('/me/events','POST',$FBcreateAnTestEvent).'">
Create a test event</a>';
echo $resp;
When is echoing the php-sdk create immediately the Event so it's better to put it in a ajax or in action linked page in a form
For FanPage use FQL link
If You parse the FBuser admin_pages and filter by APPLICATION field and/or filter by your FBpage id you can get this user FBpages admin access_token's. Of Course you need the manage_pages permissions. Then you need admin_events permission to publish to FBfanPage's. I create an FanPageEvent with GraphApi link like this:
$pageAccessToken = $facebook->api('/' . $YOURPAGEID . '/?fields=access_token');
$resp = '<a href="https://graph.facebook.com/'.$pageAccessToken['id'].'/events
?access_token=' . $pageAccessToken['access_token'] . '
&method=POST
&name='.$FBcreateAnTestEvent['name'].'
&start_time='.$FBcreateAnTestEvent['start_time'].'
&location='.$FBcreateAnTestEvent['location'].')">
Create a test event</a>';
Then voila I have allot of other things to do with this for handle it with Ajax but this is the two way of adding an Event's to Facebook from a website administrating way... All this it's not very intended for personal profile event create so it's more difficult to spam FBpages and or FBapp/FBwebapp.
I'm French speaking so excuse my poor English... ;)
精彩评论