Facebook API Upload Video by URL to Media Library - python

We have been searching for weeks but can't figure out how to upload videos or images with the API to the Media Library.
Eventually we need a video id generated by the upload API to use in our ad creative.

You can make a call to the advideos endpoint like so:
params = {
'file_url': YOUR_URL,
'access_token': YOUR_ACCESS_TOKEN
}
url = "https://graph.facebook.com/v13.0/{act_xxxxxxxxxx}/advideos"
r = requests.post(url, params)
response = r.json()

Related

How to add tags to image uploaded to imgur api from python?

I am programming a bot so that I can upload local images to my Imgur account, but I also want to add tags of each image from Python
Here is my code:
import requests
import base64
headers1 = {'Authorization': 'Bearer Xxxx',}
params = {
'title':f'uwu',
'description':'hello',
'name':'Hey',
'add_tags':'Fortnite',
'image': base64.b64encode(open('cosmetico.png', 'rb').read())}
r = requests.post(f'https://api.imgur.com/3/image', headers=headers1, data=params)
data = r.json()["data"]["link"]
id = r.json()["data"]["id"]
I have tried to add add_tags or tags but none work.
I would like to be able to add the tags:
But I can't find a way to do it.

Can't find a way to get Twitch API information through requests.py

I am stuck on this API thing. I want to print the incoming json file (channel points in specific) but it just prints the whole page in html format. Here is my code:
import requests
import json
client_id = secret
oauth_token = secret
my_uri = 'https://localhost'
header = {"Authorization": f"Bearer {oauth_token}"}
url = f'https://id.twitch.tv/oauth2/authorize?client_id={client_id}&redirect_uri={my_uri}&response_type=id_token&scope=channel:read:redemptions+openid&state=c3ab8aa609ea11e793ae92361f002671&claims={"id_token":{"email_verified":null}}'
response = requests.get(url, headers=header)
print(response.text)
My hypothesis is that either the url or the header is the problem. The twitch API is made for c# or js originally but I don't know how to convert that information to python.
I would also like to know how to do the "PING" and "PONG" thing that Twitch is writing about in the API
response.text show the html text
response.json show the json
tell me if it work now
response.json() will return you the data in JSON format

How do I solve an error related with APIs

i wold like to obtain info about an API but i get this error:**{"message":"You are not subscribed to this API."}**How can I solve this?My code is this one:
url = "https://imdb8.p.rapidapi.com/title/get-top-stripe"
querystring = {"currentCountry":"US","purchaseCountry":"US","tconst":""}
headers = {
'x-rapidapi-host': "imdb8.p.rapidapi.com",
'x-rapidapi-key': ""
}
response = requests.request("GET", url, headers=headers, params=querystring)
print(response.text)```
One needs to subscribe to a particular API on RapidAPI Hub. You can do that by visiting the pricing page of an API. I believe you're using IMDb API. The Basic plan is free of this IMDb API.
You can subscribe to any API by following the steps below:
Search API -> Go to the Pricing page -> Choose a plan (according to your need) -> Click on Subscribe button.
Once you subscribed, you would be able to test and connect to an API.

Etsy API python image upload

does anyone use python for adding listings to Etsy using API?
I am using requests_oauthlib, but keep getting error when want to upload image to listing. Other functions, like listing creation etc. are working. Code of image upload:
self.oauth = OAuth1(self.api_key,
client_secret=self.api_secret,
resource_owner_key=self.oauth_token,
resource_owner_secret=self.oauth_token_secret)
def upload_picture(self):
url = "https://openapi.etsy.com/v2/listings/{listing_id}/images"
headers = {
"Content-Type": "multipart/form-data",
}
request = {
'image': ('img8.jpg', open('./img8.jpg', 'rb'), 'image/jpeg'),
}
r = requests.post(url=url, params=request, auth=self.oauth, headers=headers)
print(r.content)
error:
oauth_problem=signature_invalid
Thanks in advance!
I wasn't able to do it like that. I'm not sure why.
But below worked for me:
etsy = OAuth1Session(
ApplicationKey,
ApplicationSecret,
token, token_secret
)
url = "https://openapi.etsy.com/v2/listings/{listing_id}/images"
request = { 'image': open('./img8.jpg', 'rb') }
response = etsy.post(url, files = request)
I'm new to both OAuth & Etsy API

How to create video captions (.srt) for a Facebook page using Graph API?

According to the Graph API v2.x, Facebook allows client applications to create captions for an existing video by uploading .srt files. See https://developers.facebook.com/docs/graph-api/reference/v2.5/video/captions/. Has anyone ever gotten this to work ?
My graph API create captions requests return with a 200 response and {'success': True}, but afterwards the Facebook video doesn't contain any captions. However, when I use the browser to upload the same .srt files, it works.
I'm using Python and the requests library to send my requests:
r = requests.post(url, files={"filename.en_US.srt": open(abspath, 'rb')})
What am I missing here?
The python call is wrong, it should be:
r = requests.post(url, files={'captions_file': ("filename.en_US.srt":
open(abspath, 'rb'), "application/octet-stream"})
In that case the API returns the same response, but the captions are added to the video. See also https://developers.facebook.com/bugs/677584865713231/

Categories