I am trying to use the Facebook graph sdk using the following code:
import facebook
def get_facebook_post(post_id, access_token):
# Initialize the Graph API client
graph = facebook.GraphAPI(access_token=access_token, version="2.1")
# Get the post object
post = graph.get_object(id=post_id, fields="permalink_url,properties,via,updated_time,type")
# Print out all of its fields
for field in post:
print(f"{field}: {post[field]}")
def handler(pd: "pipedream"):
print(pd.inputs)
token = pd.inputs["facebook_groups"]["$auth"]["oauth_access_token"]
post = get_facebook_post(pd.steps["trigger"]["event"]["id"], token)
print(post)
# Return data for use in future steps
return {"foo": {"test": True}}
I am getting inconsistent results. Sometimes it works and sometimes I get: “ModuleNotFoundError
No module named ‘facebook’”. Any idea why this is happening?
It seems like you’re trying to use the facebook package, but it’s not available in the Pipedream environment by default. To use the Facebook Graph API in Pipedream, you can make HTTP requests using the axios package from @pipedream/platform. Here’s an example of how to get a Facebook post using the Graph API with axios:
Replace the facebook package usage with this code, and it should work consistently.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.