I get the following error:
AttributeError: module 'facebook' has no attribute 'GraphAPI'
When I run the following code:
import facebook
import re
token = "EAA..." # removed my access token for security reasons
graph = facebook.GraphAPI(token)
profile = graph.get_object("100036636053395")
posts = graph.get_connections(profile['id'],"posts")
for post in posts['data']:
try:
graph.put_object(post['id'],"likes")
except:
continue
Knowing that I made sure my python script is NOT named facebook
. I'm using python3 and I've installed the facebook
module using:
pip3 install facebook-sdk
As discussed in the comments, the problem was that there is some file called facebook.py
in the working directory. So, when the Original Poster was running import facebook
, it didn't import the facebook-sdk
package, but it imported the script.
How to solve this? simple, rename your script so the interpreter doesn't get confused.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.