skip to Main Content

I am trying to upload reel with Graph API using Python.
I’m getting an error every time I try to upload video.

Error:

{"debug_info":
{"retriable":false,"type":"NotAuthorizedError","message":"User not authorized to perform this request"}}

Note: I have given every possible permission to my app and page.

Code:

import requests
import os
import json

Title ="Title of the video"
title = Title
description = title

source = f"F:proj_ytTofbdownloads{Title}.mp4"
files = {'source': open(source, 'rb')}
file_size = os.path.getsize(source)
print("File Size is :", file_size, "bytes")

def Initialize():
    url = f"https://graph.facebook.com/v13.0/{page_id}/video_reels?upload_phase=start"
    payload = {
        'access_token': token,
    }
    r = requests.post(url, data = payload)
    return r.json()["video_id"]


video_id=Initialize()
print(video_id)

def Upload():
    url = f"https://rupload.facebook.com/video-upload/v15.0/{video_id}"
    payload ={
        'access_token': token,
        'offset': 0,
        'file_size': file_size,
    }
    r = requests.post(url, files=files, data=payload)
    return r.text

print(Upload())

Output:

{"debug_info":{"retriable":false,"type":"NotAuthorizedError","message":"User not authorized to perform this request"}}

2

Answers


  1. Your Upload code seem bit wrong if you refer on documentation

    def Upload(vidid, size, filedata):
        url = f"https://rupload.facebook.com/video-upload/v13.0/{vidid}"
        payloadUp = {
            'Authorization': 'OAuth ' + page_access_token,
            'offset': "0",
            'file_size': str(size),
        }
    
        print(payloadUp)
        r = requests.post(url, data=filedata, headers=payloadUp)
        return r.text
    

    with parameter like this

    files = {'source': open(mp4_path, 'rb')}
    file_size = os.path.getsize(mp4_path)
    

    and then you called it like this

    Upload(video_id, file_size, files)
    

    Note: I successfully upload it on fb reels and published it, but I dont what happen the video failed to convert without error notice.

    Login or Signup to reply.
  2. i have the same issue can u help me pls
    {"debug_info":{"retriable":false,"type":"NotAuthorizedError","message":"User not authorized to perform this request"}}

    this is my code :

    import requests
    import Config
    import json
    import time

    def Facebook_Reels():

    post_url_init = f'https://graph.facebook.com/v18.0/{Config.PAGE_ID}/video_reels'
    
    payload_init = {
    
            'upload_phase': 'start',
            'access_token': Config.ACCESS_TOKEN,
            }
    
    r_init = requests.post(post_url_init, data = payload_init)
    print(r_init.text)
    video_id = r_init.json()["video_id"]
    print(video_id)
    
    post_url_upload = f'https://rupload.facebook.com/video-upload/v18.0/{video_id}'
    payload_upload = {
        "Authorization": "OAuth " + Config.ACCESS_TOKEN,
      'file_url': 'https://www.speilobrudaz.com/Reels_1.mp4',
    }
    
    
    r_upload = requests.post(post_url_upload, data=payload_upload)
    print(r_upload.text)
    

    Facebook_Reels()

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search