How can I construct a link to view a message on fa

2019-08-25 02:46发布

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

1条回答
小情绪 Triste *
2楼-- · 2019-08-25 03:23

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;
查看更多
登录 后发表回答