snarfed / bridgy

📣 Connects your web site to social media. Likes, retweets, mentions, cross-posting, and more...
https://brid.gy
Creative Commons Zero v1.0 Universal
718 stars 52 forks source link

facebook: v2.0 api no longer allows lookup by username #350

Closed snarfed closed 9 years ago

snarfed commented 9 years ago

...or at least, that's what we think so far. irc discussion. i'm still trying to find an explicit confirmation in their docs. the upgrade guide and platform changelog say the username field was removed from user objects in responses, but nothing about looking up by username.

the problem is that for users with usernames, FB redirects their posts to URLs that use their username instead of their id, e.g. https://www.facebook.com/snarfed.org/posts/10100929680893833 . you can look up and write to some FB posts (like that one) by bare post id, /10100929680893833, but not others, e.g. https://www.facebook.com/ben.werdmuller/posts/10101055597765779 vs /10101055597765779. we don't yet know what causes the difference.

the latter ones work if you prefix the user id, e.g. USERID_POSTID. (username prefix doesn't work.) so we'd need to do that for publish to like/comment on/share them. however, we can't get the user id, so we're hosed. :(

thanks to @kylewm for raising and pinpointing this.

kylewm commented 9 years ago

Some dead ends...

snarfed commented 9 years ago

here's a radical proposal: switch from the current POSSE model to PESOS. it would take a lot of work, but it would bring a lot of benefits.

...man oh man i wish i had the bandwidth right now to actually implement it!

kylewm commented 9 years ago

So I think I've found a reliable (for now) way to find someone's app scoped user id, but I still can't find a way to access those posts via the API.

An unversioned, unauthenticated call to https://graph.facebook.com/stephanie.rodgers.980 gives their global user ID, then an unversioned, authenticated call to https://graph.facebook.com/4705326 gives a link to https://www.facebook.com/app_scoped_user_id/10100593893240028/

So, I have the user ID now: 10100593893240028. I had hoped that this would mean I could get {user_id}_{post_id} now, but no!

/v2.2/10100593893240028_10100777887638778 /v2.2/10100777887638778

both fail with the same error message.

{
  "error": {
    "message": "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api",
    "type": "GraphMethodException",
    "code": 100
  }
}
snarfed commented 9 years ago

so infuriating, huh? regardless, interesting, nice find.

i assume both calls are using the v1 api, since the URLs are unversioned. https://developers.facebook.com/docs/graph-api/reference/v2.1/user/ids_for_business might give us a v2.x alternative for the second part, but I suspect there's still no 2.x way to look up by username. sigh.

snarfed commented 9 years ago

@kylewm and i have been discussing euthanizing facebook liking and commenting entirely. :(

i'm going to collect all the options here, no matter how crazy:

kylewm commented 9 years ago

scrape the global (non-app-scoped) user id from the profile page. e.g. right now, an unauthenticated fetch of https://www.facebook.com/snarfed.org includes 6 instances of 212038. i expect those will gradually disappear, but still.

This wouldn't help us would it? The global user ID doesn't seem to refer to anything inside the API (unless that person has signed up for bridgy prior to the switch to the new API).

kylewm commented 9 years ago

And I think we should definitely post a question to SO either way... for posterity if nothing else. I'll donate 500 karma points or whatever to the bounty :)

snarfed commented 9 years ago

i think we can still use the global user id, or at least get somewhere with it.

first, if i get a bridgy access token in the explorer and look up a global user id, e.g. https://developers.facebook.com/tools/explorer?method=GET&path=100000224384191 , that at least works. second, we just need a user id to attach to the object id to make a composite id that we can comment or like against, right? it seems like it should work. i know, fb api, yeah, right...but i'll try.

kylewm commented 9 years ago

let me know if you have better luck than i did... with user id 1740230476, app scoped id 4494578659463, and post id 10200383182099046, all 3 variations fail :(

/v2.2/10200383182099046 /v2.2/1740230476_10200383182099046 /v2.2/4494578659463_10200383182099046

snarfed commented 9 years ago

here's a bunch more research and observations. this is basically just fodder for an eventual stack overflow question; no really new information or conclusions, sadly.

a couple notes: the graph explorer links here use access tokens that include read_stream. other permissions too, but i think that's the critical one. i'm also going to be using users who haven't installed bridgy, which i think is important...? who knows. :/

kylewm commented 9 years ago

SO question posted! http://stackoverflow.com/questions/28337331/facebook-graph-api-find-graph-object-from-post-url

snarfed commented 9 years ago

yay, thank you! fingers crossed!

snarfed commented 9 years ago

we've sadly concluded that our research here is correct, and the way forward is to shut down bridgy publish support for facebook likes and comments. sad day in indiewebland. :/

props and thanks to @kylewm for his help with this!

julien51 commented 9 years ago

This is so sad :(

kylewm commented 9 years ago

@julien51 definitely a bummer, but just to be clear facebook backfeed and facebook publish for notes and articles both still work and show no signs of stopping :) there was some confusion about that in the channel yesterday.

julien51 commented 9 years ago

Ha! Indeed. But still, it upsets me when APIs are changed/removed unilaterally, but I guess there is a reason for using protocols, rather than APIs!

petermolnar commented 9 years ago

If it helps, I'm using this to import comments/likes, but I do it by post: https://github.com/petermolnar/keyring-reactions-importer/blob/master/importers/keyring-reactions-facebook.php

For me, it worked, but there are glitches.

snarfed commented 9 years ago

thanks @petermolnar! fortunately this bug only killed bridgy publish for FB. backfeed is still working fine.

kylewm commented 9 years ago

hi @petermolnar thanks from me too :) it looks like you're using the /v2.2/USERID_POSTID format to find posts from syndication links. there's two problems that break this approach for bridgy:

  1. When replying to a random post on Facebook (e.g. to someone who does not use bridgy), we cannot (by design) find the other user's app-scoped ID
  2. USERID_POSTID doesn't work reliably, some post types or some users have a different format that is harder to guess
snarfed commented 9 years ago

re #2, here's an example of code we use to try different id formats and merge the results (!) (:sob:): snarfed/granary@15b633e222e65205df33781d939cdcd20382fa39

petermolnar commented 9 years ago
  1. When replying to a random post on Facebook (e.g. to someone who does not use bridgy), we cannot (by design) find the other user's app-scoped ID

I wasn't aware of this earlier but I've read the conversation since. This is genuine madness from Facebook.

  1. USERID_POSTID doesn't work reliably, some post types or some users have a different format that is harder to guess

I've noticed that, especially with pretty old entries, like 2009.

To be honest, I'm very close to the point to leave the whole sh*t behind, including Twitter with their ridiculously restricted API.

snarfed commented 9 years ago

huh. here's something interesting in the 2.4 API changelog (search for Declarative Fields):

To try to improve performance on mobile networks, Nodes and Edges in v2.4 requires that you explicitly request the field(s) you need for your GET requests. For example, GET /v2.4/me/feed no longer includes likes and comments by default, but GET /v2.4/me/feed?fields=comments,likes will return the data. For more details see the docs on how to request specific fields.

they've supported the fields param for a while, but afaik it was always optional for all edges before 2.4. bridgy uses 2.2, so it's probably not the root cause of us seeing partial objects...but who knows. plus we'll have to do it eventually anyway!