i am receiving the timeline of a fb page, including events.
The given picture for all Entries is usually a low res thumbnail.
I tryed querying for higher res images using the object id like this:
FacebookRequest($session, 'GET', '/' . $objectId . '?fields=images', []);
But i get an error:
#100 Tried accessing nonexisting field (images) on node type (Event)
Is there any way to get the high-res pictures for events in the timeline?
Am i doing something wrong here?
The Event node type don't have an images field, but a Photo node have one.
So you should first get '/' . $objectId . '?fields=cover' to get the cover photo node id, and then call '/' . $coverId . '?fields=images'.
Related
Ok I have been stuck on this for a few weeks now. I'm using the Front Email API for a business use case and have created an iterative function to (attempt to) get multiple pages of query results.
A quick overview of the API (endpoint) I'm using for context:
The "events" endpoint returns a list of records based on the parameters given in the query (like before/after/between certain times, types of events, etc.)
If the query results in more than 100 records, a "next" pagination link is generated for the next page(s) of results. There is no "page=n" parameter in the query URL, you only get the "next page" link from the response of the previous query (which is fairly unique)
A side note, the initial base_url for the first query, and the base_url of the "next page" link are two different urls (i.e. the initial call is https://api2.frontapp.com and the second is https://companynamehere-inc.api.frontapp.com), so this is taken into consideration in my querying function.
My environment looks like this:
As you can see, I query the initial URL using the external Func_Query_Front_API function, then begin the iteration; While the next page link is not null, keep feeding the next links returned from the previous calls back into the function to get the next page of results. I deconstruct the links given to the function into a base, relative path and body/params so that I can use this logic in both Desktop and Online Service (don't ask).
It's difficult to describe the results I get, because sometimes in the preview window, it just clocks and clocks and doesn't return any results with the API not being queried at all (confirmed from Postman and the rate limit remaining number in the response headers). When I do get results back, it's a massive list of records (way more than what I'm querying for/expecting to receive) that contains lots of duplicates. It's almost like the initial (or the second) query URL is being looped over and over again, but not the "next" page's links? Like it's somehow stuck in a semi-infinite loop while the "next" link is not null from the initial response only, so it just repeats the same query over and over again re-using the same "next" page link.
Now, unfortunately I cannot provide my bearer token for this API as it's private company info returned by the API, but I'm wondering if the issue is with my syntax in the code that someone can spot and steer me in the right direction. The querying function itself works when invoked on its own, and everything looks like it SHOULD work, but it's just not doing what I think the code is saying it should do.
I understand it's not much to go on, but I'm out of options in trying to debug this thing. Thanks!
UPDATE
I think what MIGHT help here is a working code written in Python that might help to translate what I'm looking for into Power BI, so I've provided a working code in Python below (again though, the bearer token is not provided, but the syntax should make things a bit clearer). The code closely resembles what I've already made in Power BI as well so hopefully this helps things a bit?
import requests
from time import sleep
########################################
# GLOBAL VARIABLES
########################################
_event_types_filter = "assign&q[types]=archive&q[types]=comment&q[types]=inbound&q[types]=outbound&q[types]=forward&q[types]=tag&q[types]=out_reply"
_after = 1667506000
_page_limit = 100
_bearer_token = "Bearer XXXXXXXXXXXXXXXXXXXXXXXXXX"
_init_base_url = "https://api2.frontapp.com"
_relative_path = "events"
_init_body = "limit=" + str(_page_limit) + "&q[after]=" + str(_after) + "&q[types]=" + _event_types_filter
_headers = {'authorization': _bearer_token}
_init_query_url = _init_base_url + "/" + _relative_path + "?" + _init_body
########################################
# FUNCTION - Query the API
########################################
def Func_Query_Front_API(input_url):
#print(input_url)
# Deconstruct the url into its separate parts
splitted_input_url = input_url.split("?")
input_url_base = splitted_input_url[0].replace("/events", "")
input_url_body_params = splitted_input_url[1]
# Query the API
response = requests.request("GET",
input_url_base + "/" + _relative_path + "?" + input_url_body_params,
headers=_headers)
# Get the "next" link from the response
next = response.json()["_pagination"]["next"]
# Return the response and the "next" link
return response, next
########################################
# MAIN PROGRAM START
########################################
# List to add the response data's to
Source = []
# Make the initial request and add the results to the list
init_response, next = Func_Query_Front_API(_init_query_url)
Source.append(init_response)
# While the "next" link(s) are not None, query the current
# "next" link for the next page(s) of the query
while next != None:
response, next = Func_Query_Front_API(next)
Source.append(response)
sleep(1)
print(Source)
print("Done!")
I've been having a recurring issue today. I'm trying to display the photos from an album. For some reason everything works fine on the Graph Explorer using graph and fql (https://developers.facebook.com/tools/explorer/ ) but when I pull it into the app I always get an empty array returned.
I do have the correct permissions for this request too all permissions on this app are email, user_about_me, publish_actions, user_photos
The call's I have tried that are doing this are below and they all give me the same results.
$photos = $facebook->api('/'.$album_id.'/photos/');
// or
$photos = file_get_contents('https://graph.facebook.com/'.$album_id.'/photos/?access_token=' . $access_token);
// or
$params = array(
'method' => 'fql.query',
'query' => "SELECT images, src FROM photo WHERE album_object_id = " . $album_id,
);
$photos = $facebook->api($params);
It has returned the album contents once or twice, but out of the hundreds of times i've tested this 99.99% of the time its a blank array/json coming back.
Anyone know of a similar issue with this at all.
I need help understanding whether or not this is the intended behavior or if it's something that is not supported. What I want to do is upload a photo to a Facebook page post that is targeted to a specific country.
The steps I take are:
1) Upload the photo to a public album (e.g. Timeline Photos)
2) Retrieve the uploaded photo id from the album
3) Create an attachment to the post with the photo id from step #2
The problem is that I'm now uploading a photo to a public album that is not targeted to a specific country. What I would like to do is to have BOTH the photo(s) and page contents be restricted by targeting. I see a picture parameter in the api, but I believe this is just for setting the page's profile picture.
Any ideas on how this may be accomplished or whether or not this is even possible? Any code examples would also be welcomed.
After playing around with this more I found that I had to set the 'source' parameter to point to a file in my local file system (pointing to a remote file did not work). Not sure if the latter may be accomplished. Also, you have to make a call to setFileUploadSupport with true.
Pseudo code via PHP:
//Create a temporary file somewhere
$contents = ...
$tmpfname = tempnam(sys_get_temp_dir(), $prefix);
$handle = fopen($tmpfname, "w");
fwrite($handle, $contents);
fclose($handle);
//Add to params
$params['source'] = '#' . $tmpfname
$fb = FB_sdk::instance(true);
$fb->setFileUploadSupport(true);
$fb->api('[url to page]/photos', 'POST', $params);
I am trying to post pictures to customers' pages. There may or may not be a "Wall Photos" album in the page.
In scenarios where there is not a pre-existing "Wall Photos" album how would I create / request the creation of a wall photo album?
I am using Koala and I can create albums, but I cannot create albums with type = "wall".
here is the code I am using to create / find albums:
def get_photo_album(facebook_id)
# Looking for a pre-existing WALL PHOTO album
p "============= Getting Wall Photos album for fbid #{facebook_id}"
album = get_album facebook_id, 'Wall Photos'
unless album
p ' ======= Album FAIL 1 - getting Photos '
album = get_album facebook_id, FALLBACK_ALBUM_NAME
unless album
p ' ========== Album FAIL 2 - MAKING Phtoos '
#graph_client.put_object facebook_id, 'albums', 'name' => FALLBACK_ALBUM_NAME
sleep 3 # wait 3 seconds to let facebook make and fiddle with new album
album = get_album facebook_id, FALLBACK_ALBUM_NAME
unless album
p ' ##################### UTTER ALBUM FAIL '
raise "Cannot use alternative photo album"
end
end
end
if album && album.length > 0
album
else
# ensure that there is an album.
raise "Cannot use alternative photo album"
end
end
def get_album(facebook_id, name)
params = {'name' => name};
albums = #graph_client.get_connections(facebook_id, "albums", params)
p "Found #{albums ? albums.length : 0} albums named #{name} for fbid #{facebook_id}"
albums = albums.reject do |a|
a['name'] != name
end
p "Found #{albums ? albums.length : 0} albums named #{name} for fbid #{facebook_id} AFTER filtering for name"
pp albums
albums.length >0 ? albums[0] : nil
end
end
And here is the Koala code I am using to put the picture itself
def put_image(facebook_id, params)
params = sanitize_params(params)
params = encode_necessary_params(params)
picture = URI.decode(params['picture'])
photo_album = get_photo_album(facebook_id)
photo_album_id = photo_album['id']
params = params.reject do |key, value|
key == 'metadata_type'
end
p ' -------------------------------------- PUT PICTURE ----------------------------'
p "fbid:#{facebook_id}, message: #{params['message']}, picture: #{picture}"
p ' -------------------------------------- PUT PICTURE ----------------------------'
out = #graph_client.put_picture picture, {:message => params['message']}, photo_album_id
Statsd.increment("posts")
out
rescue Exception => ex
handle_error(ex)
end
I have tried several variations including:
putting 'type' => 'wall' in the #graph_client.put_object parameters: doesn't post the image at all
creating an album named 'Wall Photos' - the album appears, but the posts don't look like wall posts.
To be clear: *The ultimate goal is for all posts to this album to have "big" previews - full column width, not tiled 1" previews. *
Any help would be appreciated.
What you're trying to do isn't going to be possible - the Wall Photos album is a special album which is generated from photos posted to feed, and there is no API available to post photos that way - if you post to /photos they go into an album specifically for the app.
However, all is not lost. If you're willing to embrace newer functionality, you'll both be able to meet your goal of having large photos in feed whilst also achieving greater viral potential for your app. The answer is Open Graph Actions. Specifically User Generated Photos in Open Graph
The process for this is relatively simple:
Create an Open Graph action and object for your app (do this from the Developer App Dashboard for that particular app), this can be anything depending on what your app does, but, for example, Instagram uses 'took' as their OG action and 'a photo' as their OG object. This means that posts from that app look like "Matthew took a photo with Instagram" and show the photo below. Which action you want to use is up to you.
Request publish_actions permission from your app users, if you haven't been already.
Make API calls to:
https://graph.facebook.com/me/YOURAPPNAMESPACE:YOURACTION?
YOUROBJECTTYPE=URLWHEREYOUROGOBJECTISLOCATED&
image[0][url]=URLOFPHOTOYOUWANTTOADD&
image[0][user_generated]=true
You'll also need to sign this API call with the access token for that user, or I believe, if you have publish_actions for that user, you can make the above call to /USERID instead of /me and use your app's access token and it will work.
As you can see from the documentation this will give you the full sized photo that you're after and having it be created by an Open Graph action allows for a whole host of extra virality if you incorporate extras such as OG action links, authenticated referrals etc.
I manage to sent a photo from my server to a users album on facebook.
But this photo is not automaticly seen on his wall. And specifically it is not seen as a big photo, like how photos from albums are shown on a wall.
So I suppose I have to do a second request to tell facebook to put the photo on the wall.
I have these 2 requests:
$ret_obj = $facebook->api('/me/photos', 'POST',
array(
'source' => '#/var/www/cover/test.jpg',
'message' => $_POST['msg']
)
);
This returns for example:
[id] => 358313274248558 [post_id] => 100001736648729_358281023575116
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'message' => $_POST['msg'],
'object_attachment' => $ret_obj['id']
)
);
I have tried for the 'object_attachment' 358313274238558, 100001796648729_358281027575116 and 358281027575116. But facebook tells me that those are not correct.
So how on earth can we add a photo to a wall, which we just put in an album, and which we want to show in a large format (not as a little thumbnail).
If there is another way, without using albums, that is fine with me.
Please help. I know there have been a few questions already about photo uploads to facebook here on stackoverflow, I think I have read them all about 10 times already. It seems there is no answer yet. Somebody said we could post to /me/links but facebook doesn't seem to be able to handle links like http(s)://www.facebook.com/photo.php?fbid=358309510905631 anymore.
I have changed the ids in this post so they are not linked to actual stuff, they are here as examples.
Thanks
edit:
Ok, it seems a post of an image to an album is also a post of a big image to the wall IF the user allows the app to do public stuff. Because I was developing, I told the app to not do public stuff and only show stuff to me personally.
So there is no need to do 2 requests, just adding a photo to the album is enough to have it appear big on the users wall IF the user allows app activity to be public.
It is still somewhat confusing that a second request seems unable to also add the foto in a large size to the wall.