Fetching photos uploaded by a user - php

I have used the Facebook graph link in my site, I have tried for the last two days but I am not able to fix this problem. For two months this code has been working fine but right now it is not working.
Here is the Link
https://graph.facebook.com/157705150944797/photos/uploaded
Why do I get this error?
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
But when I use the following link I will get a response
https://graph.facebook.com/157705150944797/photos/
{
"data": [
{
"id": "212708942111084",
"from": {
"category": "Local business",
"category_list": [
{
"id": "206284062724685",
"name": "Roofer"
}
],
"name": "Blue Sky Roofing, Inc.",
"id": "157705150944797"
},
"picture": "https://m.ak.fbcdn.net/sphotos-e.ak/hphotos-ak-xap1/v/t1.0-9/p130x130/284949_212708942111084_583574_n.jpg?oh=3554b061f512bb97cb577049578d5532&oe=54D26E47&__gda__=1427888341_67dd755838624aa1e322faa03d8e4325",
"source": "https://m.ak.fbcdn.net/sphotos-e.ak/hphotos-ak-xap1/v/t1.0-9/284949_212708942111084_583574_n.jpg?oh=8e26df9a434160f154dc0a4ad6690fad&oe=54D99C4B&__gda__=1424573780_940c191fc86f99e5316f39a70336606c",
"height": 445,
"width": 445,
"images": [
{
"height": 445,
"width": 445,
"source": "https://m.ak.fbcdn.net/sphotos-e.ak/hphotos-ak-xap1/v/t1.0-9/284949_212708942111084_583574_n.jpg?oh=8e26df9a434160f154dc0a4ad6690fad&oe=54D99C4B&__gda__=1424573780_940c191fc86f99e5316f39a70336606c"
},
...
I don't know why I get that error when I use this link. I want to get all the uploaded photos in the site.
https://graph.facebook.com/157705150944797/photos/uploaded

Related

Facebook Graph - Get a high quality video from API

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.

Picking one random video from YouTube API JSON Response (PHP)

Let's say I do a simple youtube search using the YouTube API v3, and I get a response like this:
{
"kind": "youtube#searchListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/1MwZbx-vX21eNjUJjkUlNHKCIhI\"",
"nextPageToken": "CAIQAA",
"regionCode": "US",
"pageInfo": {
"totalResults": 412,
"resultsPerPage": 2
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/q2KHbIuwnAhM64HgrqhBqc5xvTI\"",
"id": {
"kind": "youtube#video",
"videoId": "gpZvuZEiINA"
},
"snippet": {
"publishedAt": "2014-03-30T11:46:50.000Z",
"channelId": "UCCaE0Bj6NI-y8_yL1FpcJUw",
"title": "Depression-90` instrumental (download link)",
"description": "E-Mail: ensari5500#gmail.com\nNew old school instrumental with download link ,Enjoy the beat, I hope you like it!\nPlease comment, rate and subscribe if you like this beat\nI appreciate YOUR support! Peace and respect",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/gpZvuZEiINA/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/gpZvuZEiINA/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/gpZvuZEiINA/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Ekii020 90` OLDSCHOOL - BOOMBOOMBAP INSTRUMENTALS",
"liveBroadcastContent": "none"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/HXRyGhFaD4Cn0wvF5XPMJKX5tNQ\"",
"id": {
"kind": "youtube#video",
"videoId": "G7ThqpcuPTI"
},
"snippet": {
"publishedAt": "2017-08-05T23:30:24.000Z",
"channelId": "UCsFmkkSVNgvihycqqtjSXgA",
"title": "Homeless (Dark Sad Piano Hip Hop Rap Instrumental Beat)",
"description": "http://rightbeatradio.com/product/homeless/\n\nI wrote a song about a humble man I met yesterday. We spoke for a while. He just wanted to talk. He was homeless.\n\nI cut some pieces from a few jazz recordings and put them behind a simple piano riff.\n\nThis music has a lot of feeling. Perfectly describes how I felt after our conversation.\n\nTake care.\n\n89 bpm\n\nrightbeatradio.com\ntwitter.com/rightbeatradio",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/G7ThqpcuPTI/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/G7ThqpcuPTI/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/G7ThqpcuPTI/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Right Beat Radio",
"liveBroadcastContent": "none"
}
}
]
}
I would like to generate, say, 10 results, but then only pick 1 (one) random [item] from the response. How can I randomize the results, and only pick one of them from this entire response?
I've seen functions such as shuffle() and array_rand() but these don't seem to be the functions that I need.
I have also seen a snippet that goes like this:
$array = json_decode($JSON, true);
$random_entry = array_rand($array['items'], 1);
$json_data = json_encode($random_entry);
I've tried that, but it returns only strings like "nextPageToken" or "kind", etc.
I would like to pick one entire [item] and grab all of its relevant [snippet] data, such as channelId, title, description, thumbnails, etc.
Can anyone point me in the right direction?
Try this
$array = json_decode($JSON, true);
$items = $array['items'];
$random_key = array_rand($items, 1);
$json_data = json_encode($items[$random_key]);
array_rand() return array key, not array value.

JSON API Plugin for wordpress not returning the right things

I create a mobile application for my site in static html, now i want use ajax to take my posts, pages, titles, images, etc.. from my wordpress original site.
For this, the best solution i think is use the JSON API plugin -> https://wordpress.org/plugins/json-api/
I already installed, and it's working good in the pages, except for the main page, it's not sending the right thinks for my mobile app.
Anyone knows what is the problem? This is a problem with my wordpress site or maybe a plugin problem?
It's sending this:
{
"status": "ok",
"count": 1,
"count_total": 1,
"pages": 1,
"posts": [
{
"id": 1689,
"type": "post",
"slug": "teste",
"url": "http://myurlsite.com/teste/",
"status": "publish",
"title": "Teste",
"title_plain": "Teste",
"content": "<p>[123-contact-form i523156]</p>\n",
"excerpt": "<p>[123-contact-form i523156]</p>\n",
"date": "2013-12-10 20:11:14",
"modified": "2013-12-10 20:11:14",
"categories": [
{
"id": 1,
"slug": "sem-categoria",
"title": "Sem categoria",
"description": "",
"parent": 0,
"post_count": 1
}
],
"tags": [],
"author": {
"id": 1,
"slug": "admin",
"name": "admin",
"first_name": "Administrador",
"last_name": "Wemaster",
"nickname": "admin",
"url": "",
"description": ""
},
"comments": [],
"attachments": [],
"comment_count": 0,
"comment_status": "open",
"custom_fields": {
"cro_sidebar": [
"1"
],
"cro_sidebarsel": [
"0"
],
"cro_readmore": [
"1"
],
"cro_showpromo": [
"1"
]
}
}
]
}
If u observe, it's returning a post, not a page:
"type": "post",
"slug": "teste",
"url": "http://myurlsite.com/teste/",
"status": "publish",
"title": "Teste",
"title_plain": "Teste",
I delete the test post and now it~s returning this:
{"status":"ok","count":0,"count_total":0,"pages":0,"posts":[]}
Try accessing the post via this url:
http://www.yourdomain.com/api/get_page/?slug=<page-slug>
or use the page id instead:
http://www.yourdomain.com/api/get_page/?id=<page-id>
I've tested both and both work with that plug-in.
For more information read this information by the developer(s).

Accessing url for images in tumblr search API

I am trying to access the urls of the first images that show up for tumblr searches using the tag search api. Below is the json for the test search I'm using.
{
"meta": {
"status": 200,
"msg": "OK"
},
"response": [
{
"blog_name": "m00tzman",
"id": 37918165271,
"post_url": "http://m00tzman.tumblr.com/post/37918165271/test-image-for-tumblr-a…",
"slug": "test-image-for-tumblr-api-thingy",
"type": "photo",
"date": "2012-12-14 18:13:25 GMT",
"timestamp": 1355508805,
"state": "published",
"format": "html",
"reblog_key": "IwlKk9r4",
"tags": [
"g6845e"
],
"highlighted": [ ],
"note_count": 29,
"caption": "<p>test image for tumblr api thingy</p>",
"photos": [
{
"caption": "",
"alt_sizes": [
{
"width": 500,
"height": 628,
"url": "http://25.media.tumblr.com/af60fbe390c487125501e50b37781317/tumblr_…"
},
{
"width": 400,
"height": 502,
"url": "http://25.media.tumblr.com/af60fbe390c487125501e50b37781317/tumblr_…"
},
{
"width": 250,
"height": 314,
"url": "http://25.media.tumblr.com/af60fbe390c487125501e50b37781317/tumblr_…"
},
{
"width": 100,
"height": 126,
"url": "http://24.media.tumblr.com/af60fbe390c487125501e50b37781317/tumblr_…"
},
{
"width": 75,
"height": 75,
"url": "http://24.media.tumblr.com/af60fbe390c487125501e50b37781317/tumblr_…"
}
],
"original_size": {
"width": 500,
"height": 628,
"url": "http://25.media.tumblr.com/af60fbe390c487125501e50b37781317/tumblr_…"
}
}
]
}
]
}
My problem is that I am not able to echo out the url for the "original size" image. Here is my code so far:
<?php
$search = file_get_contents('http://api.tumblr.com/v2/tagged?tag=g6845e&api_key=(api key)');
$tumblrdata = json_decode($search, true);
$photos = $tumblrdata['photos']['original_size'];
$url = $photos['url'];
echo $url;
?>
Any guesses on what is going wrong here?
Try
$photos = $tumblrdata['response']['photos'][0]['original_size'];

Posting to Facebook results randomly in Status messages or Posts

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

Categories