This app is posting to the user's timeline, using PHP and Facebook's PHP API implementation. This is working right now, for over several weeks already.
The following PHP code is being used to post a message:
if($hasPhoto === TRUE)
{
// Post to FB with picture
$facebook->setFileUploadSupport(true);
$result = $facebook->api("/me/photos", "post", array(
'message' => $message,
'place' => $place,
'source' => '#' . $photo
));
}
else
{
// Post to FB without picture
$result = $facebook->api("/me/feed", "post", array(
'message' => $message,
'place' => $place
));
}
This is working properly, except there are two formattings of the $result:
array ('id' => '103240856515XXX', )
array ('id' => '100004900175XXX_103239809849XXX', )
The Graph API documentation tells us the following:
A post from Facebook Platform: https://graph.facebook.com/19292868552_10150189643478553
A status message on the Facebook Page: https://graph.facebook.com/10150224661566729
This means the used PHP code generates posts ór status messages. I don´t see any relation between the textmessages, photos, dates, or authors. It seems to happen randomly.
The following shows the relationship from our data between the format of the id and whether a photo is attached.
select count(*) from fbposts where facebookpostid like '%\_%' and hasphoto = 1; -- 90
select count(*) from fbposts where facebookpostid like '%\_%' and hasphoto = 0; -- 87
select count(*) from fbposts where facebookpostid not like '%\_%' and hasphoto = 1; -- 47
select count(*) from fbposts where facebookpostid not like '%\_%' and hasphoto = 0; -- 54
Why does this behaviour happen? How to force a Post? The reason why this is relevant is because Post does have a Privacy property which I would like to query.
Update:
Querying a status message 545778052106XXX, given by the FB API, with a photo, gives me:
{
"id": "545778052106XXX",
"from": {
"name": "Jeffrey Krist",
"id": "100000226354XXX"
},
"name": "My message!",
"picture": "http://photos-f.ak.fbcdn.net/hphotos-ak-ash3/522827_545778052106XXX_1151562XXX_s.jpg",
"source": "http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash3/s720x720/522827_545778052106XXX_1151562XXX_n.jpg",
"height": 720,
"width": 720,
"images": [
{
"height": 2048,
"width": 2048,
"source": "http://sphotos-f.ak.fbcdn.net/hphotos-ak-ash3/s2048x2048/522827_545778052106XXX_1151562XXX_n.jpg"
}, .. lots more
],
"link": "https://www.facebook.com/photo.php?fbid=545778052106402&set=p.545778052106XXX&type=1",
"icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPXXX.gif",
"place": {
"id": "182665821805XXX",
"name": "A company name",
"location": {
"street": "My street 13", ..
}
},
"created_time": "2012-11-01T08:35:20+0000",
"updated_time": "2012-11-01T08:35:20+0000",
"comments": ...
"likes": ...
}
Querying a post message using a id from the FB API gives me:
{
"id": "100003331805XXX_299609210160XXX",
"from": {
"name": "Some name",
"id": "100003331805XXX"
},
"message": "My message",
"picture": "http://photos-e.ak.fbcdn.net/hphotos-ak-ash3/560724_299609200160XXX_789651XXX_s.jpg",
"link": "https://www.facebook.com/photo.php?fbid=299609200160XXX&set=a.285494101571XXX.69331.100003331805XXX&type=1&relevant_count=1",
"name": "Photo album name",
"icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPXXX.gif",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/100003331805XXX/posts/299609210160XXX"
},
{
"name": "Like",
"link": "https://www.facebook.com/100003331805XXX/posts/299609210160XXX"
}
],
"privacy": {
"value": "ALL_FRIENDS", ...
},
"place": {
"id": "174171872642XXX", ...
},
"type": "photo",
"status_type": "added_photos",
"object_id": "299609200160XXX",
"application": {
"name": "My app", ...
},
"created_time": "2012-12-21T22:33:59+0000",
"updated_time": "2012-12-21T23:30:39+0000",
"likes": ...
"comments": ...
}
Querying a composed id, _ ('100000226354XXX_545778052106XXX'), which is message with a photo, gives me:
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
There is no need to force a post when each status message is a post object.
Status message object 10100948019328597
Post object userid_10100948019328597
Status message object
{
"id": "10100948019328597",
"from": {
"name": "phwd",
"id": "13608786"
},
"message": "Happy Thanksgiving you cool Canadians!",
"updated_time": "2012-10-08T23:17:27+0000",
"likes": {
"data": [
],
"paging": {
"next":
}
}
}
Post object
{
"id": "13608786_10100948019328597",
"from": {
"name": "phwd",
"id": "13608786"
},
"message": "Happy Thanksgiving you cool Canadians!",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/13608786/posts/10100948019328597"
},
{
"name": "Like",
"link": "http://www.facebook.com/13608786/posts/10100948019328597"
}
],
"privacy": {
"description": "Public",
"value": "EVERYONE",
"friends": "",
"networks": "",
"allow": "",
"deny": ""
},
"type": "status",
"status_type": "mobile_status_update",
"created_time": "2012-10-08T23:17:28+0000",
"updated_time": "2012-10-08T23:17:28+0000",
"likes": {
"data": [
]
},
"comments": {
"count": 0
}
}
The best way to check would be to compare /me/statuses vs /me/posts
Related
There is json response:
{
"id": "1234567890123456789",
"creation_date": 12345678,
"event": "WAITING_PAYMENT",
"version": "2.0.0",
"data": {
"product": {
"id": 213344,
"name": "Product Name",
"has_co_production": false
},
"affiliates": [
{
"name": "Affiliate name"
}
],
"buyer": {
"email": "buyer#email.com"
},
"producer": {
"name": "Producer Name"
},
"commissions": [
{
"value": 0.65,
"source": "MARKETPLACE"
},
{
"value": 3.10,
"source": "PRODUCER"
}
],
"purchase": {
"approved_date": 1231241434453,
"full_price": {
"value": 134.0
},
"original_offer_price": {
"currency_value": "EUR"
"value": 100.78,
},
"price": {
"value": 150.6
},
"order_date": "123243546",
"status": "STARTED",
"transaction": "HP02316330308193",
"payment": {
"billet_barcode": "03399.33335 33823.303087 198801027 2 876300015000",
"billet_url": "https://billet-link.com/bHP023163303193",
}
},
"subscription": {
"status": "ACTIVE",
"plan": {
"name": "plan name"
},
"subscriber": {
"code": "12133421"
}
}
}
}
My question is how to extract data["buyer"]["email"] in PHP ?
I only need to extract the email information from the buyer table inside the data table.
First, you need to decode the json to a PHP array (or an object), then you can access the requested information from the decoded data.
$data = json_decode('the json string most place here', true);
$email = $data['buyer']['email'];
Place your json string in the first argument of json_decode() function.
I am using this API call to get the Page's Post details and this one includes the Post's Video Source.
https://graph.facebook.com/v5.0/{page id}/posts?fields=from{id,name,picture},status_type,attachments,full_picture,picture,message,story,properties,created_time,shares,comments.limit(0).summary(true).as(comments),likes.limit(0).summary(true).as(likes),permalink_url
This API call responds with these data:
{
"from": {
"id": "123123",
"name": "abcd",
"picture": {
"data": {
"height": 50,
"is_silhouette": false,
"url": "https://scontent.fmnl4-6.fna.fbcdn.net/v/t1.0-1/cp0/p50x50/123123_123123",
"width": 50
}
}
},
"status_type": "added_video",
"attachments": {
"data": [
{
"media": {
"image": {
"height": 405,
"src": "https://fb.com/adsfasdf",
"width": 720
},
"source": "https://video-fb-source.com.fb.mp4?_nc_cat=1231&cb=3"
},
"target": {
"id": "240206797735633",
"url": "https://www.facebook.com/asd1asdfasdf"
},
"title": "test 123123",
"type": "video_autoplay",
"url": "https://www.facebook.com/hahahae/videos/240206797735633/"
}
]
},
"full_picture": "https://scontent.fmnl4-6.fna.fbcdn.net/v/t15.5256-10/145288627_240218977734415_42016794327.jpg?",
"picture": "https://scontent.fmnl4-6.fna.fbcdn.net/v/t15.5256-10/145288627_240218977734415_42016794327.jpg?",
"message": "haha hahahaha",
"properties": [
{
"name": "Length",
"text": "41:20"
}
],
"created_time": "2021-02-15T18:00:01+0000",
"shares": {
"count": 7
},
"comments": {
"data": [
],
"summary": {
"order": "ranked",
"total_count": 1,
"can_comment": true
}
},
"likes": {
"data": [
],
"summary": {
"total_count": 16,
"can_like": true,
"has_liked": false
}
},
"permalink_url": "https://www.facebook.com/xxxx/posts/xxx/",
"id": "xxxx_123123_xxx"
},
I get the Post's Video Source from the attachments.data[0].media.source json, then every time I get the video, I download it on my local.
My problem with that is it does not return a high-quality video, it's a bit pixelated. Unlike in Facebook, when you go directly to the video URL, there's a 1080p option.
How can I get a high-quality video that I can download through Facebook's Graph API?
Thanks.
I've some trouble with parsing a JSON file into a MySQL database. It's an export of some Facebookstats.
Because I've multiple export of multiple pages, it's important that I've the corresponding ID in the database.
The JSONfile (or cURL from Facebook) looks like this:
{
"data": [
{
"name": "impressions",
"period": "week",
"values": [
{
"value": 123456789,
"end_time": "2016-01-01T08:00:00+0000"
},
{
"value": 12345678,
"end_time": "2016-01-02T08:00:00+0000"
},
{
"value": 1234567,
"end_time": "2016-01-03T08:00:00+0000"
},
{
"value": 123456,
"end_time": "2016-01-04T08:00:00+0000"
},
{
"value": 12345,
"end_time": "2016-01-05T08:00:00+0000"
}
],
"title": "Weekly Impressions",
"description": "The number of impressions seen of any content associated with your Page. (Total Count)",
"id": "101010101010\/insights\/page_impressions\/week"
}
],
"paging": {
"previous": "1",
"next": "2"
}
}
I would, ideally, parse this data into a MySQL database that looks like this:
id value end_time
101010101010 123456789 2016-01-01T08:00:00+0000
101010101010 12345678 2016-01-02T08:00:00+0000
101010101010 1234567 2016-01-03T08:00:00+0000
101010101010 123456 2016-01-04T08:00:00+0000
101010101010 12345 2016-01-05T08:00:00+0000
I hope someone had some ideas :-)
Use json_decode(). Example:
$jsonString = '{
"data": [
{
"name": "impressions",
"period": "week",
"values": [
{
"value": 123456789,
"end_time": "2016-01-01T08:00:00+0000"
},
{
"value": 12345678,
"end_time": "2016-01-02T08:00:00+0000"
},
{
"value": 1234567,
"end_time": "2016-01-03T08:00:00+0000"
},
{
"value": 123456,
"end_time": "2016-01-04T08:00:00+0000"
},
{
"value": 12345,
"end_time": "2016-01-05T08:00:00+0000"
}
],
"title": "Weekly Impressions",
"description": "The number of impressions seen of any content associated with your Page. (Total Count)",
"id": "101010101010\/insights\/page_impressions\/week"
}
],
"paging": {
"previous": "1",
"next": "2"
}
}';
Then decode it to an associative array:
$assocData = json_decode($jsonString, true); //Setting second optional parameter to true makes it return an associative array.
Then access it however you want:
$data = $assocData['data'];
This question already has answers here:
How to loop through PHP object with dynamic keys [duplicate]
(16 answers)
Closed 6 years ago.
I got a json data in return in my php script and this json data is stored in my variable. Now i would like to check the "price" for name "express" in php. Please guide me the way to extract the data in php.
$serviceTypesJSON = json_decode($rawBody, true);
{
"services": {
"service": [
{
"code": "INT_PARCEL_COR_OWN_PACKAGING",
"name": "Courier",
"price": "85.13",
"max_extra_cover": 5000,
"options": {
"option": [
{
"code": "INT_TRACKING",
"name": "Tracking"
},
{
"code": "INT_SMS_TRACK_ADVICE",
"name": "SMS track advice"
},
{
"code": "INT_EXTRA_COVER",
"name": "Extra Cover"
}
]
}
},
{
"code": "INT_PARCEL_EXP_OWN_PACKAGING",
"name": "Express",
"price": "40.13",
"max_extra_cover": 5000,
"options": {
"option": [
{
"code": "INT_TRACKING",
"name": "Tracking"
},
{
"code": "INT_SIGNATURE_ON_DELIVERY",
"name": "Signature on delivery"
},
{
"code": "INT_SMS_TRACK_ADVICE",
"name": "SMS track advice"
},
{
"code": "INT_EXTRA_COVER",
"name": "Extra Cover"
}
]
}
},
{
"code": "INT_PARCEL_STD_OWN_PACKAGING",
"name": "Standard",
"price": "31.40",
"max_extra_cover": 5000,
"options": {
"option": [
{
"code": "INT_TRACKING",
"name": "Tracking"
},
{
"code": "INT_EXTRA_COVER",
"name": "Extra Cover"
},
{
"code": "INT_SIGNATURE_ON_DELIVERY",
"name": "Signature on delivery"
},
{
"code": "INT_SMS_TRACK_ADVICE",
"name": "SMS track advice"
}
]
}
},
{
"code": "INT_PARCEL_AIR_OWN_PACKAGING",
"name": "Economy Air Parcels",
"price": "23.77",
"max_extra_cover": 500,
"options": {
"option": [
{
"code": "INT_EXTRA_COVER",
"name": "Extra Cover"
},
{
"code": "INT_SIGNATURE_ON_DELIVERY",
"name": "Signature on delivery"
}
]
}
}
]
}
}
Now how to extract the "name": "Express", "price": "40.13", from this variable? I would like to take the express, standard, Economy Air Parcels price. Please help me how to extract the exact data from this json mixed data
var text = '{"name":"John Johnson","street":"Oslo West 16","phone":"555 1234567"}';
var obj = JSON.parse(text);
document.getElementById("demo").innerHTML =
obj.name + "<br>" +
obj.street + "<br>" +
obj.phone;
You can use this method.
I've gone through a few examples and documentations and kind find a solution update a nested object in the this result set.
I can add one (if one does not exist)
I can append to it (if one does exist)
Can't figure out how to delete a selected entry.
Is there a method I can use (using the php client) to add an entry if it does not exist / update an entry if it does exist / delete the second entry.
I'm inheriting this problem and am new to Elastic search.
Thanks.
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "products",
"_type": "categories",
"_id": "AUpRjtKZfXI7LIe9OpNx",
"_score": 1,
"_source": {
"name": "Primary",
"description": "Primary Category",
"slug": "Primary",
"created": "2014-12-16 00:25:22",
"parent": [
{
"name": "First One",
"description": "Test",
"id": "ae74ea4e2e865ed3fd60c18a06e69c65",
"slug": "first-one"
},
{
"name": "Second One",
"description": "Testing Again",
"id": "c8dbe5143c8dfd6957fa33e6cea7a0a8",
"slug": "second-one"
}
]
}
}
]
}
}
Do you want to do all three in the same operation?
Deleting the second nested object is achieved through a script which removes the second element:
PUT /products
{
"mappings": {
"categories": {
"properties": {
"parent": {
"type": "nested",
"properties": {
"name": { "type": "string" },
"description": { "type": "string" },
"id": { "type": "string", "index": "not_analyzed" },
"slug": { "type": "string" }
}
}
}
}
}
}
PUT /products/categories/1
{
"name": "Primary",
"description": "Primary Category",
"slug": "Primary",
"created": "2014-12-16 00:25:22",
"parent": [
{
"name": "First One",
"description": "Test",
"id": "ae74ea4e2e865ed3fd60c18a06e69c65",
"slug": "first-one"
},
{
"name": "Second One",
"description": "Testing Again",
"id": "c8dbe5143c8dfd6957fa33e6cea7a0a8",
"slug": "second-one"
}
]
}
POST /products/categories/1/_update
{
"script" : "ctx._source.parent.remove(1)",
"lang": "groovy"
}
GET /products/categories/1
So in PHP code (using the official PHP client), the update would look like:
$params = [
'index' => 'products',
'type' => 'categories',
'id' => 1,
'body' => [
'script' => 'ctx._source.parent.remove(1)',
'lang' => 'groovy'
]
];
$result = $client->update($params);