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!

David23C
  • 1
  • 1
  • 1

3 Answers3

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)
balderman
  • 22,927
  • 7
  • 34
  • 52
0

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

  • I think the OP is looking for a Python cURL library like there is in PHP. – anjanesh Aug 26 '21 at 09:26
  • I think there is no such thing! – ali.k.mirzaei Aug 26 '21 at 09:29
  • There is pycurl.io – anjanesh Aug 26 '21 at 10:56
  • This is what I've seen in a related post (https://stackoverflow.com/questions/26000336/execute-curl-command-within-a-python-script), 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. – David23C Aug 27 '21 at 08:28
0

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

Azerpas
  • 304
  • 2
  • 10