skip to Main Content

I am trying to get the data from social bakers API for Facebook but getting an error while requesting it

The error says:

Authorization is not valid.

Here is my code:

import json 
import requests
from requests_oauthlib import OAuth1

token = 'mytoken'
headers = { 'Authorization' : 'Token ' + token }
r = requests.get('https://api.socialbakers.com/0/facebook/profiles', headers=headers)
j = json.loads(r.text)

They have given a guide to request their API.

How should I make my request using their format?

2

Answers


  1. Looks like your headers aren’t correct, try running the following code:

    import requests
    from requests_oauthlib import OAuth1
    
    token = 'mytoken'
    headers = { 'Authorization' : 'Basic ' + token }
    r = requests.get('https://api.socialbakers.com/0/facebook/profiles', headers=headers)
    j = r.json()
    

    hope this helps

    Login or Signup to reply.
  2. Following the documentation example; https://api.socialbakers.com/#security-and-authentication
    Using Aladin|OpenSesame as token and secret, first we need to use b64encode on them:

    import requests,base64
    
    encoded_auth_text = base64.b64encode(b'Aladdin'+b':'+b'OpenSesame')
    
    

    Then in order to have that in the header format of the documentation:

    token = encoded_auth_text.decode('utf-8')
    headers = { 'Authorization' : 'Basic ' + token }
    print(headers)
    

    The header should make sense with the one of the documentation, now we are ready to make the request:

    response = requests.get(url='https://api.socialbakers.com',
                                headers=headers)
    
    print(response)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search