-1

I want to send friend name as a user in get_object()in below code for getting his public posts. But I am getting error

raise GraphAPIError(result) facebook.GraphAPIError: (#803) Cannot query users by their username (tayyab.rasheed.545)

user = 'tayyab.rasheed.545' #is giving error
#user = 'BillGates'         #is working fine.
# user = 'me'               #is working fine.

graph = facebook.GraphAPI(access_token)
profile = graph.get_object(user)
posts = graph.get_connections(profile['id'], 'posts')

Why is the error? I think I am doing something wrong. BillGates and me is working fine then why not tayyab.rasheed.545 Profile of friend is 'https://www.facebook.com/tayyab.rasheed.545'

Awais
  • 101
  • 1
  • 1
  • 5
  • btw, this has been answered already, please use the search function first: http://stackoverflow.com/questions/30886468/facebook-cannot-query-users-by-their-username-solution – andyrandy Sep 09 '16 at 10:53

2 Answers2

1

Why is the error?

Because Facebook removed the username field from the API with v2.0, and as the error message says, you can not query user profiles by their username any more.

BillGates and me is working fine then why not `tayyab.rasheed.545

BillGates simply is a Facebook Page, and not a user profile.

(And me has nothing to do with the username in the first place.)

CBroe
  • 91,630
  • 14
  • 92
  • 150
0

It is not possible to get public posts of any user. Even for you own public posts, you need to authorized yourself with the user_posts permission.

Edit: Please don´t change your question, especially when there is an answer already. CBroes answer is correct. You are not supposed to get any data of users who did not authorized your App anyway.

andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • @luschn, I think this answer was meant for a different question …? – CBroe Sep 09 '16 at 10:46
  • oh...that is weird...i guess it was a caching issue, thanx! – andyrandy Sep 09 '16 at 10:47
  • no, it was actually meant for this question, but he completely edited it, look at the history...not cool :/ – andyrandy Sep 09 '16 at 10:48
  • Ah yeah, right, saw that “original” question before already and your answer to it, so I assumed this was another, individual question, and the answer got posted to that one accidentally. – CBroe Sep 09 '16 at 10:50
  • @luschn Really sorry. I thought I should not increase the database by one question by adding one new question. That is why, I edited that to a new one. – Awais Sep 09 '16 at 10:58
  • my answer did not make any sense anymore. new topic, new question. but you should really use the search function next time before asking, that error comes up quite often and it´s a well known one. if you really don´t want to "increase the database", that would be the way to go (google, SO search) ;) – andyrandy Sep 09 '16 at 11:02