Search code examples
jsonpython-3.xfacebook-graph-apipython-requeststoken

Facebook Graph API returns a different response on a different script but same -not invalid- tokens


I am trying to make a simple python script that posts a text message to a facebook page using requests.

I actually managed to succeed this feat, however, when I add the same logic to a bigger project of mine, a certain request returns a different json.

According to this page https://developers.facebook.com/docs/pages/access-tokens I can exchange the short lived user token I generate in the graph explorer tool for a long lived one that lasts 60 days. This worked for me until now. When I run the same functions, same variables on another .py file that includes other logic as well the request does not return this line:

"expires_in": SECONDS-UNTIL-TOKEN-EXPIRES

And of course later on if I continue the logic and use the token it returns (which is the same) for, let's say, a make_post function the request prints

{'error': {'message': '(#200) If posting to a group, requires app being installed in the group, and \\\n          either publish_to_groups permission with user token, or both manage_pages \\\n          and publish_pages permission with page token; If posting to a page, \\\n          requires both manage_pages and publish_pages as an admin with \\\n          sufficient administrative permission', 'type': 'OAuthException', 'code': 200, 'fbtrace_id': 'AqYMMeOcOniWAGgEEtsEURs'}

Why does it not successfully return, the user token had not expired and it has the requires rights. Furthermore I tested this in a smaller .py file and it worked.

Another thing I found out here https://developers.facebook.com/support/bugs/523165725596520/?join_id=f1ff8392b49675c here is that other people have actually reported the same issue but it has been closed as 'intended by design' however there is no information of a solution.

Running the request in my browser also does not work correctly.

Do you have any ideas? I am completely clueless. Thank you very much in advance


Solution

  • As @CBroe in a comment said, the expires_in didn't have anything to do with my error. The token it returns if valid. The issue I had later on had to do with the url I was parsing