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

我的梦境 提交于 2019-12-25 04:15:52

问题


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:


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;


来源:https://stackoverflow.com/questions/7747622/how-can-i-construct-a-link-to-view-a-message-on-facebook-com-if-i-have-the-messa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!