Add coordinate data to a Facebook Event - facebook

Right now, as far as I know, the Facebook Graph API lets you add a location to an event as a string value. Users are able to add location data to events manually though, by specifying a Facebook place or an address, and it looks like Facebook natively uses Bing maps to display the location. Does anyone know if there are any plans to update the API to let developers add location data properly to events?

The API already supports location data.
Facebook will display the map correctly if you specify a location_id which could be the ID of a place page
Here is a code example...
$facebook->setFileUploadSupport(true);
$event = array(
'name' => stripslashes ($name),
'description' => stripslashes ($description),
'start_time' => $start_time,
'end_time' => $end_time,
'privacy_type' => $privacy,
'location_id' => $location_id
);
$event[basename($flyer_file)] = '#' . realpath($flyer_file);
try {
$result = $facebook->api('me/events','post',$event);
} catch (FacebookApiException $e) {
$error = "Facebook Error: $e";
}

Related

Does tweet_mode=extended work with the Twitter statuses/user_timeline API?

There is no mention of tweet_mode at https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html
I am wondering if perhaps I am using the wrong API to be able to take advantage of tweet_mode?
In my application, I supplied the tweet_mode=extended argument and it had no effect. My code...
// Load the Tweets.
$args = array(
'screen_name' => $username,
'exclude_replies' => 'true',
'include_rts' => 'true',
'tweet_mode' => 'extended',
'count' => $numitems,
);
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$tweets = $connection->get('statuses/user_timeline', $args);
if (!empty($tweets)) {
foreach ($tweets as $tweet) {
$text = $tweet->full_text;
// etcetera
Yes, you can use tweet_mode with the statuses/user_timeline API. Retweets are a special case, though. Check the retweeted_status object, as described at https://dev.to/kehers/formatting-tweets-a-look-at-extended-tweets-retweets-and-quotes-n5j
In short, if a tweet is a retweet, the extended tweet must be accessed at $tweet->retweeted_status->full_text. Thus, it's necessary in your code to check if each tweet object has a retweeted_status property.

Create charts for a facebook page via open graph and php

I have created a FB App that grants the following permissions from the user:
1. manage_pages
2. read_insights
By using the app, the user can create a new tab on a page and delete it when this is necessary.
Apart from that, I want to give the option to the user to see some basic stats regarding the page(s) that she creates the tab(s).
For example, I want to retrieve the page views for a certain page for a specific period.
In order to do this I used the following code:
$today = date("Y-m-d");
$until = strtotime($today);
$since = strtotime("2013-08-01");
$pageID = "123";
$page_info = $facebook->api("/$pageID?fields=access_token");
$access_token = $page_info['access_token'];
$params = array(
'access_token' => $access_token,
'since' => $since,
'until' => $until,
);
$insights = $facebook->api("/{$pageID}/insights/page_views/",
"GET",
$params
);
print_r($insights);
The problem is that the result is...somehow empty. More precisely, I receive the following:
Array
(
[data] => Array
(
)
[paging] => Array
(
[previous]=>https://graph.facebook.com/123/insights/page_views/since=1370059200&until=1375329600
[next]=>https://graph.facebook.com/123/insights/page_views/since=1380600000&until=1385870400
)
)
When I use, the same logic to receive insights for my app (without using $token in the $params array), I receive the right data.
In addition to that, I was wondering if there is a way to create charts with this data (directly from FB).
Thx,
Antonis
I managed to solve the problem.
The returning array was empty, because I forgot to check if the user is logged in through facebook...
Regarding the charts, I didn't find any solution directly from facebook, so I used the Charts.js plugin.

I want to create post with web site preview

I want to create a post with web site preview. It must be similar as on screenshot.
How do I create a post with web preview? I want to add it on pages.
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:#"Post with web preview", #"message", nil];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:#"%#/feed", myself.pageID]
parameters:dict HTTPMethod:#"POST" completionHandler:nil];
More info about posting links (what you call "post with web site preview") here:
http://developers.facebook.com/docs/reference/api/link/
I asumme you have your Facebook APP with your permissions set, and that you're using PHP-sdk classes. Anyway, the proccess is the same for any language, just changing the way you write it. Also, you need the user Access Token with the proper permission set.
Using the PHP-sdk from Facebook, process would be:
// Load FB class, and init it
require_once("facebook.php");
$config = array();
$config['appId'] = 'YOUR_APP_ID';
$config['secret'] = 'YOUR_APP_SECRET';
$facebook = new Facebook($config);
// You set the User Access Token (you need to have it previously to this: Because you
// requested before, or because you obtain it from Facebook)
$facebook->setAccessToken( $user_access_token );
try {
// Set the link params:
if ( isset($config['link']) ) {
$args = array(
'link' => $link_url //Url to be linked
, 'name' => $link_titulo //Box title
, 'description' => $link_descripcion //Box Description
, 'picture' => $link_foto //Photo to be posted
, 'message' => $link_message //Message over the "link box"
);
// Post in the User/FB_Page wall
$facebook->api('/me/feed', 'post', $args);
}
} catch (FacebookApiException $e) {
$fbError = $e->getResult();
$result = array(
'tipo' => 'error'
, 'code' => $fbError['error']['code']
, 'text' => $fbError['error']['message']
);
print_r($result);
}
Update
After reading your answer to my comment, I think you're looking just for the CSS and the layout. You can find something to achive the post formatting here:
http://jsfiddle.net/5NYD5/3/
This can be done using multiple ways,
If you are using facebook API then its easy, just like on FB(image will be automatically fetched)
Dim fb As FacebookClient = New FacebookClient('access_token')
Dim args As Dictionary(Of String, Object) = New Dictionary(Of String, Object)()
args("message") = "Your Message to be posted"
args("link") = "http://www.example.com"
fb.Post("/me/feed", args)
I hope this will do,
else if you are not using FB API then its comparatively long way to grab image or create snapshot, of site manually. Just like search engine crawlers crawl after entering website. Its long way but yes possible.

Create Facebook event as Page with rGraph API

I am trying to create an event on Facebook on behalf of the page i own with Graph API.
From FB documentation i read that it is done like this:
POSTing name and start_time (other things are optional) to
https://graph.facebook.com/{Page_ID}/events
with proper premissions (create_event, manage_pages)
playing around with this in Graph API Explorer i do get event created but it is done under my own profile rather than Page.
So is it possible to create the event under the Page i own rather than my profile?
PS i double checked the page id so it is not my profile id
PPS I know there are allready many discussions about this here, but unfortunatley i couldnt find a straightforward answer to my question.
So i figured this out myself. I needed to post it with page access token. heres the code
$page_info = $this->fb->api('/' . $page_id . '?fields=access_token');
if (!empty($page_info['access_token'])) {
$path = realpath(APPPATH . '../path/to/img');
$args = array(
'access_token' => $page_info['access_token'],
'start_time' => $start_time,
'description' => $description
'name' => $name,
'location' => $loaction
);
$img = 'img.jpg';
if ($upload) {// if picture is needed
$args['#' . $img] = '#' . $path . '/' . $img;
$this->fb->setFileUploadSupport(true);
}
$res = $this->fb->api("/" . $this->input->post('fb_event'), "post", $args); // should give back event id
}

How to present an Unlike link for a Facebook page

I have a Facebook app which is interested in whether users like or unlike specific pages. I want to offer a link to unlike a page, as so far as I know there is no way to unlike a page programmatically using the Graph API.
Facebook provide a like button, but (again, so far as I know) no unlike button. How can I present an option to unlike a page without saying "Click here to go to the page, scroll down to the miniscule unlike link and click it"?
You can issue a DELETE request to the page_id
suppose the page id is 1234567890123
place the link as on the a page as:
Unlike
Now collect the GET parameter in the unlike.php file and fire a DELETE request through the graph api:
<?php
$fb = new Facebook(array(
'appId' => FB_APP_ID,
'secret' => FB_APP_SECRET,
'cookie' => true
));
$session = $fb->getSession();
if (empty($session))
{
$loginUrl = $fb->getLoginUrl();
echo "<script>window.top.location='{$loginUrl}';</script>";
exit;
}
$fb_liked_page = $_GET['d']; //COLLECT THE PAGE ID HERE
try
{
$status = $fb->api("/{$fb_liked_page}/likes", 'DELETE');
if ($status)
{
echo "Success, Unliked!";
}
else
{
echo "Could not unlike this page.";
}
}
catch (Exception $e)
{
var_dump($e);
}