Facebook Graph API Scheduled Posts created but not published - facebook

I'm using django-facebook's Open Facebook API to try to defer a post with an image to a facebook page. The (relevant part of the) code is:
graph_api = OpenFacebook(integration.long_lived_page_token)
message = "something"
picture = "http://example.com/image.jpg"
d = datetime.datetime.strptime('07-25-2014 06:40 pm UTC', '%m-%d-%Y %I:%M %p %Z')
timestamp = timestamp = int(time.mktime(d.timetuple()))
try:
facebook_response = graph_api.set('/{0}/feed'.format(
facebook_page_id), message=message,
link=picture, picture=picture,
scheduled_publish_time=timestamp, published=0)
except:
...
This seems to work fine (I get the post id on facebook_response) but when the time comes to post this scheduled post nothing happens. When I check at the facebook page I see an error saying 'Sorry, something went wrong publishing this scheduled post' and offers to delete it or post it then. So, I can't seem to figure out what am I doing wrong.
I found a similar question but it does not offer a good answer.
Oh, I forgot to say when I remove timestamp and published=0 parameters (i.e. I post on that exact moment), the post gets created and published on the page's feed.

Related

Facebook Graph API event-id/comments?since=2014-02-01&until=2014-02-10 , Date filter has no effect

I am trying to bring comments made on a particular event by targeting this URL: https://graph.facebook.com/1466384840257158/comments
I am passing the user_access_token
I have two comments at present on this event made on the same
day(2014-03-29)
Now I try to pass a date which should bring an empty data result/object
like this: https://graph.facebook.com/1466384840257158/comments?since=2011-01-01&until=2014-01-10
This request has no effect, it still shows me the two comment made
on the 29th
I have tried the same kind of date range on my user-id/feed and it
gave me an empty data object.
Finally i tried event-id/feed (before trying date filter) and it
gave me the following error
.
{
"error": {
"message": "An unexpected error has occurred. Please retry your request later.",
"type": "OAuthException",
"code": 2
}
}
Could you please guide me about date filter on that particular query (point4) or if you have any other idea to use date filter on comments made for an event.
Comments use Cursor-based Pagination, so you cannot use since or until on the comments endpoint (these parameters would work f.ex. for the feed endpoint).
To get the comments in a time range you have to fetch all comments from NOW to the start of the time range, f.ex. with https://graph.facebook.com/1466384840257158/comments?filter=stream&limit=1000+paging (the filter=stream will order the result with the timestamp).
USING SINCE UNTIL FOR COMMENTS on GROUP
If you want to use since and until for comments, it is not possible directly for a group. So, First you can apply it for status(feed) and then get the comments for that feed.
This works for me:
{group_id}/?fields=feed.since(08/25/2016).until(08/31/2016){from,comments{from,message}}
Why don't you try first to filter by notifications?... notifications allows you to add parameters like since. For example (using Facebook pages):
https://graph.facebook.com/PAGEID?fields=notifications.since(2015-3-31 00:00:00).limit(250).include_read(true)&{id,created_time,updated_time,unread,object,link}&access_token=ACCESSTOKEN
Once you got the json data, loop through data, get the ID and send a second request but this time using the PAGEID_POSTID edge. Something like this:
https://graph.facebook.com/PAGEID_POSTID/comments?fields=id,from{name,id},message,can_remove,created_time&limit=1000
Voahla!... there's no need to read every comment!...
Note 1: A Page access token is required, along with the manage_pages permission
Note 2: Use the parameter/field include_read to get all the notifications, even the already readed
Note 3: In the second request, use the parameter/field "filter=stream" to order the posts and get the comments made in the name of your page
Note 4: Don't forget to control the asynchronicity once you loop!
Note 5: Notifications duplicate posts, use an array to avoid to read more than one time the postUse the parameter/field include_read to get all the notifications, even the already readed
I do not know if it's too late. But, Yeah it works in the graph api version 3.3.
for example: if you wanna get comments on a post of a Facebook page you can do it like this:
You have to use page Access-token
The get Graph Request : post_id/comments?since=some_date

Comment/like-count from a facebook post

Any ideas how to get the likes/comment count from a Facebook post - fast?
My idea was to get the stats of every single post, but it takes too long.
$post = $facebook->api("/".$array['PostID']."/?fields=comments,likes", array());
$likes_count = count($post['likes']['data']);
$comments_count = count($post['comments']['data']);
I also tried to do it with a batch request like:
$buildQuery .= '{"method":"GET","relative_url":"'.$array['PostID'].'/?fields=comments,likes"}';
The problem here is, that it doesn't work, because batch requests supports only POST mode.
What should I try? Any ideas?

How can I construct a link to view a message on facebook.com if I have the message id

I am retrieving the messaging inbox with the following graph api call:
https://graph.facebook.com/me/inbox?access_token=...
It returns an array of messages that each have an identifying "id" (same as message id as returned by FQL)
I would like to be able to provide a link for the user to view a message directly on Facebook.com.
Something like: https://www.facebook.com/messages/?action=read&tid=....
That is the link you get to if you you browse to a message from facebook itself.
However I can't seem to find a way to discover the correct tid from either the Graph API or FQL.
I haven't had any luck in figuring out an alternative URL either.
This url used to work, but is broken for me now: http://facebook.com/?sk=messages&tid=...
It just redirects to the top level messaging page: https://www.facebook.com/messages/
ANY IDEAS?
Thanks so much
From graph API get to me/inbox the result set gives id as part of each object returned. This is also thread_id.
If the id you have is a string object (probably a guid), this is from Facebook's older message system storage structure. Now they've updated to a new storage structure that requires the old ones to be migrated into the new
So you have a fairly easy check:
If thread id is a long (Int64/BigInt), then you have a new thread and can use
http://www.facebook.com/messages/?action=read&tid=id.THREAD_ID
If thread id is a string then you have a older thread and can use
http://www.facebook.com/messages/?action=read&tid=THREAD_ID
many programming languages have their own form of checking the type of a value.
var threadId = (string)data.thread_id;
var longVal = 0L;
var isLong = Int64.TryParse(threadId, out longVal);
var threadUrl = (isLong) ?
"http://www.facebook.com/messages/?action=read&tid=id." + threadId :
"http://www.facebook.com/messages/?action=read&tid=" + threadId;

Facebook Credits Example on App Engine?

Are there any examples of using facebook credits on Google App Engine?
I found this blog post , but it's not complete
http://blog.suinova.com/2011/01/integrating-facebook-credits-api-into.html
I got the sample runwithfriends example working on the App Engine, tried to expand it with Credits, no luck so far.
Also searched for the FB developer forums, got nothing.
Any resources you can point me to?
What's not working:
1) When I click on the "pay with Facebook" button, I get an "Application Error" , without any error code.
-Checked the javascript console
-Checked the fb app settings
-Tried on local server and production server
2) The callback.py isn't complete, because i could not parse the signed request (no code available in py for me to learn from)
3) What I basically did was to add code from Suinova Designs (link above) to the existing Run With Friends app code. Didn't turn out as expected.
my code so far:
//payment_page.html
<html>
<table>
<tr><th>Name</th><th>Price</th><th> </th></tr>
<tr><td>Something to buy</td><td>10 FC</td><td><a href="" onclick="return buyit();">
<img src="http://www.facebook.com/connect/button.php?app_id=215638625132268&feature=payments&type=light_l" />
</a></td></tr>
</table>
// javascript
function buyit(){
FB.ui({
method:'pay',
purchase_type:'item',
order_info:{
item_id:'myitem',
title:'Something to buy',
price:2,
description:'Whatever',
image_url:'http://www.facebook.com/images/gifts/21.png',
product_url:'http://www.facebook.com/images/gifts/21.png'}
},
function(resp){
if(resp.order_id) window.top.location='http://apps.facebook.com/runwithfriends trial'; else alert(resp.error_message);
});
return false;
}
//callback.py
class FacebookPaymentRequest(webapp.RequestHandler):
def post(self):
signed_request = parse_signed_request(self.request.get('signed_request'),conf.FACEBOOK_APP_SECRET)
payload = signed_request['credits'] #credits:{buyer:int,order_id:int,order_info:{},receiver:int}
order_id = payload['order_id']
method = web.request.get('method')
return_data = {'method':method}
if method == 'payments_get_items':
order_info = payload['order_info'] #order_info:{item_id:'',title:'',description:'',price:0,image_url:'',product_url:''}
item = simplejson.loads(order_info) #needs to convert JSON string to dict
#check item,price,etc and reply
return_data['content'] = [item]
elif method == 'payments_status_update':
status = payload['status']
return_data['content'] = {'status':'settled','order_id':order_id}
if status == 'placed':
#just return settled status to Facebook, this may be called twice
order_details = simplejson.loads(payload['order_details'])
#check and log here
elif status == 'settled':
order_details = simplejson.loads(payload['order_details'])
#order_details:{order_id:0,buyer:0,app:0,receiver:0,amount:0,update_time:0,time_placed:0,data:'',items:[{}],status:'placed'}
buyer = order_details['buyer']
item = order_details['items'][0]
#now save this transaction into our database
else:
#may be refunded, canceled, log the activity here
return_data['content']['status'] = status
self.response.out.write(simplejson.dumps(return_data))
Your python code looks fairly normal so I would guess that you are simply having trouble with your authorization. Depending upon how you authorize (a process a fair amount more complicated that the credits system), you are likely being given a signed request that is only partially authorized... meaning you are authorized to access only certain parts of facebook, but generally not authorized to access the active/logged-in user (i.e. me).
You can verify this by determining if you signed_request is a full 80+ characters (as opposed to around 40). Generally I try to authenticate by deciphering the profile (signed_request), if that fails then I try to use a previously stored cookie, then if that fails I try to relogin the user. I determine failure by placing try/except around my calls to get a "me" object through the GraphAPI.

Update Facebook status using R?

Is it possible to update my facebook status from an R session?
EDIT 1: Reading the responses thus far, I would like to point out that I'm simply interested if a package already exists which provides this functionality, similar to how the lovely twitteR package does for twitter. Also, something doesn't have to be 'useful' in order to be 'fun', which is how I prefer to learn.
Edit 2: Sorry to anyone offended by me by not being more specific in how I asked my question. I have used R informally for 2 months and was told that SO was a nice place to ask questions (yes i have read the intro guide).
NB: The following only successfully logs you into facebook. I don't know why the status update at the end doesn't work, but maybe it is still of some value. It is based on a blog post over at Baratttalo back in March and which I thought would pass time on a friday afternoon.
I wasn't going to reply to this, but looking at some of the other responses and seeing as you helped me over at mathoverflow, I figured I'd give it a shot.
you'll need to install the RCurl and XML packages from http://www.omegahat.org/ (it's a pretty cool website to look at even just for fun i think).
Anyway copy and paste this:
library(RCurl)
library(XML)
log.into.facebook <- function(curl, id) {
curlSetOpt( .opts = list(postfields = paste('email=', URLencode(id$login.email), '&pass=', URLencode(id$login.password), '&login=', URLencode('"Login"'), sep=''),
post = TRUE,
header = FALSE,
followlocation = TRUE,
ssl.verifypeer = FALSE,
cookiejar = 'my_cookies.txt',
cookiefile = 'my_cookies.txt',
useragent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3'), curl = curl)
u <- "https://login.facebook.com/login.php?m&next=http%3A%2F%2Fm.facebook.com%2Fhome.php"
doc <- getURL(u, curl = curl)
return(doc)
}
get.update.stutus.form.id <- function(curl, doc) {
curlSetOpt( .opts = list(post = FALSE), curl = curl)
doc <- getURL("http://m.facebook.com/home.php" , curl = curl)
html <- htmlTreeParse(doc, useInternal = TRUE)
# this gets the post_form_id value
form.id.node <- getNodeSet(html, '//input[#name="post_form_id"]')
form.id <- sapply(form.id.node, function(x) x <- xmlAttrs(x)[[3]])
# we'll also need the exact name of the form processor page
form.num.node <- getNodeSet(html, '//form[#method="post"]')
form.num <- sapply(form.num.node, function(x) x <- xmlAttrs(x)[[1]])
form.num <- strsplit(form.num, "/")[[1]][3]
return(list(form.id = form.id, form.num = form.num))
}
# This function doesn't work. I would love to know why though as it 'looks' right to me
update.status <- function(doc, curl, id) {
form <- get.update.stutus.form.id (curl, doc)
curlSetOpt( .opts = list(post = TRUE,
postfields = paste('post_form_id=', form$form.id, '&status=', URLencode(id$status), '&update=', URLencode('"Update status"'), sep = '')),
curl = curl)
u <- paste("http://m.facebook.com", form$form.num, sep = "/")
doc <- getURL(u, curl = curl)
return(doc)
}
and here's how you use the functions above (change id values to your log in details)
id <- list()
id$status <- "Hello world!"
id$login.email <- "YOUR LOGIN EMAIL"
id$login.password <- "YOUR LOGIN PASSWORD"
# log into facebook, seems to work fine
curl <- getCurlHandle()
doc <- log.into.facebook(curl, id)
# this is the bit that doesn't work, no idea why though.
update.status(doc, curl, id)
Hope that helps a little bit, maybe it will give you an idea. Also, I think the question you asked is fine, maybe just be a bit more specific next time and so maybe you'll avoid some of the comments you've gotten here :-)
Tony Breyal
P.S. I think there IS an api for all this somewhere, but if all you're interested in is updating the status, I quite like the idea of using the twitteR package and linking the updates to facebook.
I don't think so. It would require building a package to support the Facebook API, and nobody's done that for R. (And, really, why would they? It's not the best tool for the job! And it's not like you can pull large amounts of data from Facebook to do data analysis...)
What you could do is to use the twitteR package, update your status on Twitter, then connect your Twitter and Facebook accounts to get the update into Facebook.
I must admit I would never imagine someone would ask a question like this but.. :)
Use the httpRequest package (http://cran.fiocruz.br/web/packages/httpRequest/index.html) to update your status. It's just a POST. I can't find an example in R but here is an example in PHP - it's not difficult to see what being done: http://fbcookbook.ofhas.in/2009/02/07/facebook-reveals-status-api-how-to-use-it/
Right now (December 2013) it is possible to update Facebook status using R. You only need to use RFacebook package (http://cran.r-project.org/web/packages/Rfacebook/). All You need is to set up everything (here you have tutorial - http://thinktostart.wordpress.com/2013/11/19/analyzing-facebook-with-r/) and after that there is updateStatus function, for example:
updateStatus("Here is my new status", token)
Sure, study the API and create a package.
If your question really was "has anybody already done the work for me?" then the answer may be no.
In response to the comment, the classic "This is R. There is no if. Only how." still applies. Quoting from the fortunes package:
> library(fortunes)
> fortune("Yoda")
Evelyn Hall: I would like to know how (if) I can extract some of the
information from the summary of my nlme.
Simon Blomberg: This is R. There is no if. Only how.
-- Evelyn Hall and Simon 'Yoda' Blomberg
R-help (April 2005)
>
So in short, download the twitteR package, see how it uses the RCurl package to access the Web API and do likewise for Facebook's API. Or pay someone to do it for you.