Account activity registering webhook program freeze up



I am using app authentication and get a bear token. But then when I post to register a web hook the program just freezes. It is not trying to communicate with the url I want to register as there is no activity in that log. Here is the relevant parts of my code and the debug log. The token is a valid bearer token.

DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1):

headers = {
“Host”: “”,
“User-Agent”: “My Twitter App v1.0.23”,
“Authorization”: "Bearer " + token,
“Content-Type”: “application/x-www-form-urlencoded”,
“Content-Length”: “29”,
“Accept-Encoding”: “/

data = {
“url” : callbackURL

r =“”, headers=headers, params=data)

print (r.text)


I solved it. You need to use oauth1 (i.e. user) authentication and not app authentication to get a bearer token. Here is a complete program to help similarly confused persons:

import urllib.parse
import base64
import logging
import requests
import simplejson as json
from requests_oauthlib import OAuth1


consumerKey = "XXXXX"
consumerSecret ="XXXXX"
accessToken ="XXXXX"
accessTokenSecret =“XXXXX”

url = ‘

auth = OAuth1(consumerKey, consumerSecret, accessToken, accessTokenSecret)
r = requests.get(url, auth=auth)

print (“oauth_token=”, authToken)

callbackURL = urllib.parse.urlencode({‘url’: “”})

print (“callbackURL=”, callbackURL)

data = {
“url” : callbackURL

r =“”, auth=auth, params=data)

print (r.text)