Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/Buffer/Buffer_Send_text_to_Idea.ipynb
2973 views
Kernel: Python 3

Buffer.png

Buffer - Send text to Idea

Give Feedback | Bug report

Tags: #buffer #idea #text #send #python #api

Last update: 2023-10-11 (Created: 2023-10-11)

Description: This notebook sent a text to a Buffer Idea.

Input

Import libraries

import requests import json

Setup variables

  • buffer_url: This variable holds the URL of the specific Buffer profile where you want to create a new post. Example: "https://publish.buffer.com/profile/xxxxxxxxxxx/tab/queue"

  • text: This variable contains the text content that you want to post on the Buffer profile. You can modify this string to change the content of the post.

  • cookie: This variable is used to store the cookie information from your Buffer session.

organization_id = "xxxxxxx" text = "My Buffer Idea" cookie = naas.secret.get("BUFFER_COOKIES") or "Inspect your Buffer and Copy/Paste your cookie"

Model

Send text to Idea

This function will send text to Idea using the Buffer API.

def parse_cookie(cookie): data = {} for c in cookie.split(";"): key = c.split("=", 1)[0].strip() value = c.split("=", 1)[-1].strip() data[key] = value return data def send_text_to_idea(organization_id, cookie, text): # Init result = None cookies = parse_cookie(cookie) # Base URL url = "https://graph.buffer.com/" # Headers headers = { "authority": "graph.buffer.com", "accept": "*/*", "accept-language": "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7", "content-type": "application/json", "origin": "https://publish.buffer.com", "referer": "https://publish.buffer.com/", "sec-ch-ua": '"Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117"', "sec-ch-ua-mobile": "?0", "sec-ch-ua-platform": '"Windows"', "sec-fetch-dest": "empty", "sec-fetch-mode": "cors", "sec-fetch-site": "same-site", "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36", "x-buffer-client-id": "webapp-publishing" } data = { "operationName": "CreateIdea", "variables": { "input": { "content": { "text": text, "media": [], "tags": [] }, "organizationId": organization_id, "source": "content" } }, "query": 'mutation CreateIdea($input: IdeaCreationInput\u0021) {\n ideaCreate(input: $input) {\n ... on IdeaMutationSuccess {\n success\n message\n idea {\n id\n content {\n text\n __typename\n }\n __typename\n }\n __typename\n }\n ... on CoreWebAppCommonError {\n message\n code\n error\n __typename\n }\n __typename\n }\n}\n' } res = requests.post(url, headers=headers, data=json.dumps(data), cookies=cookies) res.raise_for_status if res.status_code == 200: result = res.json() else: print(res.status_code) print(res.text) return result result = send_text_to_idea(organization_id, cookies, text) result

Output

Display result

result