0

I would like to know how to run the following cURL request using python (I'm working in Jupyter notebook):

curl -i -X GET "https://graph.facebook.com/{graph-api-version}/oauth/access_token?  
grant_type=fb_exchange_token&          
client_id={app-id}&
client_secret={app-secret}&
fb_exchange_token={your-access-token}"

I've seen some similar questions and answers suggesting using "requests.get", but I am a complete python newbie and am not sure how to structure the syntax for whole request including the id, secret and token elements. Any help would be really appreciated.

Thanks!

3

3 Answers 3

1

no need to use curl. use the below

import requests

graph_api_version = 'a'
app_id = 'b'
app_secret = 'c'
your_access_token = 'd'
url = f"https://graph.facebook.com/{graph_api_version}/oauth/access_token?grant_type=fb_exchange_token&client_id={app_id}&client_secret={app_secret}&fb_exchange_token={your_access_token}"
r = requests.get(url)
Sign up to request clarification or add additional context in comments.

2 Comments

@David23C Did you replace a,b,c,d with the real values?
Thanks - the app_id had a typo - seems to be working now
0

you can use some lib that run commands in python like subprocess. for example: subprocess.run(["curl", "google.com"])

4 Comments

I think the OP is looking for a Python cURL library like there is in PHP.
I think there is no such thing!
There is pycurl.io
This is what I've seen in a related post (stackoverflow.com/questions/26000336/…), but I am still not sure how to rewrite my code above using 'subprocess'. Are you able to show how the final code should look? I have the app_id, secret & access token.
0

Convert your Curl request to Python instantly here : https://curl.trillworks.com/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.