I’ve been trying to register the crc for an account activity API webhook. I’ve created a quick and dirty crc response using flask and a self signed SSL certificate. The code for the CRC challenge is the following:
app = Flask(__name__)
sslify = SSLify(app)
CORS(app)
@app.route('/default', methods=['GET'])
def default():
return("default!!")
# Defines a route for the GET request
@app.route('/webhooks/twitter', methods=['GET'])
def webhook_challenge():
# creates HMAC SHA-256 hash from incomming token and your consumer secret
key_bytes= bytes("my consumer secret" , 'utf-8')
data_bytes = bytes(request.args.get('crc_token'), 'utf-8') # Assumes `data` is also a string.
sha256_hash_digest = hmac.new(key_bytes, msg=data_bytes, digestmod=hashlib.sha256).digest()
# construct response data with base64 encoded hash
response = {
'response_token': 'sha256=' + str(base64.b64encode(sha256_hash_digest))
}
# returns properly formatted json response
return json.dumps(response)
context = ('cert.pem', 'key.pem')
if __name__ == "__main__":
app.run(host="0.0.0.0", port=443,ssl_context=context)
and the code to trigger the crc challenge is the following:
from requests_oauthlib import OAuth1Session
import urllib
CONSUMER_KEY = 'my consumer key'
CONSUMER_SECRET = 'my consumer secret'
ACCESS_TOKEN = 'my token'
ACCESS_SECRET = 'my secret'
twitter = OAuth1Session(CONSUMER_KEY,
client_secret=CONSUMER_SECRET,
resource_owner_key=ACCESS_TOKEN,
resource_owner_secret=ACCESS_SECRET)
webhook_endpoint = urllib.parse.quote_plus('https://52.55.57.237/webhooks/twitter')
url = 'https://api.twitter.com/1.1/account_activity/all/AccountAPI/webhooks.json?url={}'.format(webhook_endpoint)
r = twitter.post(url)
from pprint import pprint
pprint(vars(r))
Unfortunately, I keep getting a 214 error that I can’t find an explanation for. It says:
“code”:214,“message”:“Webhook URL does not meet the requirements. Please, check your SSL Configuration.”
However, I am not getting any request logged in flask, is this just because my ssl certificate is self signed? My problem is likely similar to:
which is the only instance I have found of the same error message.