facebook api how to get lat/long from user_location - php

There is a discussion here: location (lat long) using facebook api but it doesn't show how to get it...
I can get the basic info:
"location": {
"id": "104146386288393",
"name": "Newton, Massachusetts"
},
but how to I make a request using the location ID to get
{
"id": "104146386288393",
"name": "Newton, Massachusetts",
"picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQDygUYzFOcjhDoD&w=100&h=300&url=http\u00253A\u00252F\u00252Fupload.wikimedia.org\u00252Fwikipedia\u00252Fen\u00252Fe\u00252Fe6\u00252FNewton_City_Hall\u0025252C_Massachusetts.jpg&fallback=hub_city&prefix=s",
"link": "http://www.facebook.com/pages/Newton-Massachusetts/104146386288393",
"likes": 3741,
"category": "City",
"is_published": true,
"is_community_page": true,
"description": "<snipped data>",
"location": {
"latitude": 42.3369,
"longitude": -71.2097
},
"checkins": 310,
"talking_about_count": 8912
}
Here is my code for facebook:
$user_profile = (new FacebookRequest($session, 'GET', '/me?fields=id, first_name, location'))->execute()->getGraphObject(GraphUser::className());
thanks

This is what you can do:
Authorize the user with user_location
Make a GET request to /me?fields=location
Make a GET request to the location id you get in the result of /me
...meaning, you just need to do an extra API call to get latitude/longitude.

You can check with the graph api tool before implementation.
After having location id, you need to call "location_id"?fields=location to get long/lat

Related

Webhooks JSON in PHP

I've been working on a web-based system using PHP. The system is linking to the payment gateway using API and webhooks for payment notification. I've worked on everything else but webhooks are foreign to me. I've subscribed to webhooks and the payment gateway is supposed to send in JSON via the url submitted when creating webhooks. Below is the sample JSON.
{
"topic": "buygoods_transaction_received",
"id": "2133dbfb-24b9-40fc-ae57-2d7559785760",
"created_at": "2020-10-22T10:43:20+03:00",
"event": {
"type": "Buygoods Transaction",
"resource": {
"id": "458712f-gr76y-24b9-40fc-ae57-2d35785760",
"amount": "100.0",
"status": "Received",
"system": "Lipa Na M-PESA",
"currency": "KES",
"reference": "OJM6Q1W84K",
"till_number": "000000",
"sender_phone_number": "+254999999999",
"origination_time": "2020-10-22T10:43:19+03:00",
"sender_last_name": "Doe",
"sender_first_name": "Jane",
"sender_middle_name": null
}
},
"_links": {
"self": "https://sandbox.kopokopo.com/webhook_events/2133dbfb-24b9-40fc-ae57-2d7559785760",
"resource": "https://sandbox.kopokopo.com/financial_transaction/458712f-gr76y-24b9-40fc-ae57-2d35785760"
}
}
I need to capture some fields like OJM6Q1W84K,100.0 etc and store them into my db. How do I capture the JSON? The rest will be easy for me once I figure out that one. Thanks guys.

How can i fetch page data from graph with only pageid

I have a problem with graph api.
The call "https://graph.facebook.com/[pageID]" fails with the message
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
I need the full url of the facebook-page. Is there a way to get the url of a page from pageid only?
EDIT: Thank you for tips. The error was, that when the page is not public, that i cannot query infos via graph. Its also not working, when i (admin of page!) call the graph-url...
If you take a look at Page Graph API Reference there is a example url to get information about the page, include the url of the page that you want. The example url request is :
https://graph.facebook.com/19292868552
and the result is :
{
"about": "Grow your app with Facebook\nhttps://developers.facebook.com/ ",
"company_overview": "Facebook Platform enables anyone to build social apps on Facebook, mobile, and the web.\n\n",
"is_published": true,
"talking_about_count": 34563,
"username": "FacebookDevelopers",
"website": "http://developers.facebook.com",
"were_here_count": 0,
"category": "Product/service",
"id": "19292868552",
"name": "Facebook Developers",
"link": "http://www.facebook.com/FacebookDevelopers",
"likes": 1187896,
"cover": {
"cover_id": "10151298218353553",
"source": "http://sphotos-b.ak.fbcdn.net/hphotos-ak-ash4/s720x720/377655_10151298218353553_500025775_n.png",
"offset_y": 0,
"offset_x": 0
}
}
I think in your problem you put the wrong page ID.

How do i show the maps for the venue while creating an event programmatically with the PHP SDK?

When i create an event with the graph api i need to specify the venue and i would like also to show the map.
I do
$fb_event['name'] = "THis is to test latitude";
$fb_event['description'] = "And longitude!!!!";
$fb_event['start_time'] = date( "c", Ai1ec_Facebook_Event::get_facebook_start_time($event->start));
$fb_event['location'] = "Where you want";
$fb_event['street'] = "Via andrea del sarto 9";
$fb_event['city'] = "Milan";
$fb_event['latitude'] = 45.444975793404;
$fb_event['longitude'] = 9.2119209654715;
$facebook = $this->facebook_instance_factory();
try {
$result = $facebook->api( "/me/events", "POST", $fb_event );
} catch (FacebookApiException $e) {
fb($e);
}
This produce this event which show the correct street and city, but no map. If i edit the event and save, the map "Magically" appears using the street and city correctly.
In any case latitude and longitude are ignored.
What am i doing wrong?
If you compare your two test events in the Graph API explorer you'll see that Event ID 239298922846828 does not have its latitude and longitude populated, while 245655182207213 does. I'm assuming 245655182207213 is an event you've edited.
Looking at your code, you seem to be doing everything as described in the documentation. However, I've found that what is described does not always work.
What I've been seeing is that events populated from within Facebook that occur at a known venue are no longer allowing you to specify an address. Instead all they save is a venue id within Facebook which you can then drill into to get the address, etc.
Take a look at one of my events. For this event, there is no way to edit the details of this location from within Facebook, nor does the event venue details get returned with an API call. I'm using the API to pull the event details to an external website. This change caused me days of frustration.
I started seeing this behavior in late April. I haven't found any official documentation announcing this change.
When some documentation appears, what I expect the new event venue workflow will be is something like:
Query the area where your event will take place to see if a venue exists already.
If yes, get save its id.
If not, create a new community page for your venue and save its id.
Use this ID to populate the event venue.
In the end this is a known facebook bug
https://developers.facebook.com/bugs/173095916131752
Two different formats when create using the same parameters.
When create event through gql
{
"id": "xxxxxxxxxxxxxx",
"owner": {
"name": "xxxxxxxxxx",
"id": "xxxxxxxxx"
},
"name": "W1112",
"start_time": "2013-10-22",
"is_date_only": true,
"location": "Tulsa, OK, United States",
"venue": {
"latitude": 36.131388888889,
"longitude": -95.937222222222,
"street": "",
"zip": "",
"id": "109436565740998"
},
"privacy": "SECRET",
"updated_time": "2013-09-19T12:23:26+0000"
}
When create event through fb
{
"id": "xxxxxxxxxxxxxx",
"owner": {
"name": "xxxxxx",
"id": "xxxxxxxx"
},
"name": "1234",
"start_time": "2013-10-09T21:26:00+1100",
"end_time": "2013-10-25T00:26:00+1100",
"timezone": "Australia/Sydney",
"is_date_only": false,
"location": "Maroubra Junction",
"venue": {
"latitude": -33.940804216453,
"longitude": 151.23876752992,
"city": "Maroubra",
"state": "NSW",
"country": "Australia",
"id": "153993547968514",
"street": "832 anzac Parade ",
"zip": "2035"
},
"privacy": "SECRET",
"updated_time": "2013-09-19T10:50:14+0000"
}

Graph API / FQL Does not return all events for a page

Facebook Page: http://facebook.com/getwellgabby/events/ currently has 8 events on it. I can see them. Non-admins can see them and can join them.
However, when I make calls via the Graph API or FQL, only 4 future events are returned. Results can be seen here: http://getwellgabby.org/events?raw=1 (Scroll to bottom for raw response.)
FQL Query is:
SELECT eid, name, start_time, end_time, location, venue, description
FROM event WHERE eid IN ( SELECT eid FROM event_member WHERE uid = 213367312037345 ) AND end_time > now()
ORDER BY end_time asc
Inspecting individual event IDs returned via Graph API shows no difference between these events. However, when editing them via the front end, they display in different dialogs.
Two sample events follow. Both were created by the same page admin approx. 24 hours apart. The first event displays properly via an API/FQL call. The second does not. From the front end, the second event displays differently than the first.
Data below was returned using the FB Graph API Expplorer Tool using an Access Token with "create_event" privileges.
Reports Correctly:
{
"id": "344143808978921",
"owner": {
"name": "Get Well Gabby",
"category": "Non-profit organization",
"id": "213367312037345"
},
"name": "Get Well Gabby Day With The Reading Phillies",
"description": "Please join [truncated...]",
"start_time": "2012-06-10T13:30:00",
"end_time": "2012-06-10T16:30:00",
"location": "FirstEnergy Stadium",
"venue": {
"street": "1900 Centre Ave.",
"city": "Reading",
"state": "Pennsylvania",
"country": "United States",
"latitude": 40.357,
"longitude": -75.91434,
"id": "223424611014786"
},
"privacy": "OPEN",
"updated_time": "2012-04-25T14:22:57+0000",
"type": "event"
}
Does not report correctly:
{
"id": "128748077259225",
"owner": {
"name": "Get Well Gabby",
"category": "Non-profit organization",
"id": "213367312037345"
},
"name": "Get Well Gabby Day With The Wilmington Blue Rocks",
"description": "Get Well Gabby Day With [truncated...]",
"start_time": "2012-07-29T13:35:00",
"end_time": "2012-07-29T16:35:00",
"timezone": "America/New_York",
"location": "Frawley Stadium",
"venue": {
"id": "148306638522325"
},
"privacy": "OPEN",
"updated_time": "2012-04-25T18:11:35+0000",
"type": "event"
}
Note, front end dialog for the event that does not report correctly will not accept additional venue information.
You can use since and until to increase the scope of your query.
here is an example using graph api explorer and search events (shows future events)
https://developers.facebook.com/tools/explorer/135669679827333/?method=GET&path=search%3Ftype%3Devent%26q%3Da%26limit%3D100%26since%3Dnow%26until%3Dnext%20year
171535666239724/events?since=2010&until=now // all events since 2010 until now
171535666239724/events?since=now&until=2013 // all events from now until 2013
for graph api requests:
until, since (a unix timestamp or any date accepted by strtotime http://php.net/manual/en/function.strtotime.php): https://graph.facebook.com/search?until=yesterday&q=orange
The issue seems to have resolved itself for now. Thanks if someone following this issue did something at Facebook.

Can we identify the date on which someone liked my page?

How can we identity the date on which someone liked my page.
is there any way where we can identify the date on which someone liked my page ?
No. You can't even get a list of people that like your page, so you can't get a date they liked it. The only information you can get is how many people like it.
You can view a chart of how many people liked your page over time at Facebook Insights.
Well no, You can make a graph call to the statuses and feeds of a user with valid access_token to get the id and name of the people who liked the post.. The timestamp can be found for the comments though ..
{
"id": "257821xxxxxxx",
"from": {
"name": "Maxxxxxx",
"id": "100xxxxxx"
},
"message": "incredible ..",
"updated_time": "2011-09-15T11:21:15+0000",
"likes": {
"data": [
{
"id": "6xxxxxx6",
"name": "Axxxxxxxxxa"
}
]
},
"comments": {
"data": [
{
"id": "257xxxxxxxxxxxx904",
"from": {
"name": "Maxxxxxxxxxxal",
"id": "1xxxxxxxxxxxxxx"
},
"message": "htxxxxxxxxxxxxxxxxxxxxxxxxxx",
"can_remove": true,
"created_time": "2011-09-15T11:22:06+0000"
}
]
}
}

Categories