Hi everyone Im in a tangle as how to recorded, transcribe and retrieve the text from the transcription in Twilio. How do I do it? Example:
# Download the Python helper library from twilio.com/docs/python/install
from twilio.rest import TwilioRestClient
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "AC30bd8bdca7572344721eb96c15a5c0c7"
auth_token = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)
transcription = client.transcriptions.get("TR8c61027b709ffb038236612dc5af8723")
print(transcription.transcription_text)
in client.transcriptions.get, How do I get the latest transcription? I need the Uri (I believe) but have no idea how to access it/variable name.
On a side note, what alternatives to the Twilio transcription are there and how do I access the appropriate recordings in my script to transcribe?
Twilio developer evangelist here.
You can access all your transcriptions by listing them as follows:
# Your Account Sid and Auth Token from twilio.com/user/account
account_sid = "AC30bd8bdca7572344721eb96c15a5c0c7"
auth_token = "your_auth_token"
client = TwilioRestClient(account_sid, auth_token)
for transcription in client.transcriptions.list():
print transcription.transcriptiontext
You can also set the TranscriptionUrl attribute so you get notified with a transcription ID when a transcription is complete. That way you can use the code snipped you posted above.
Related
How can I test the Tweepy authentication using API v2?
My code below fails to post due to authentication however, is there any other way to test the authentication without invoking posting a Tweet (client.create_tweet) ?
import tweepy
bearer_token = "hidden"
consumer_key = "hidden"
consumer_secret = "hidden"
access_token = "hidden"
access_token_secret = "hidden"
client = tweepy.Client(bearer_token=bearer_token)
client = tweepy.Client(
consumer_key=consumer_key,
consumer_secret=consumer_secret,
access_token=access_token,
access_token_secret=access_token_secret
)
client.create_tweet(text="My first tweet")
You can use any of the methods listed in the documentation here.
I would suggest you to use some read method like get_user:
user = client.get_user('twitter')
print(user.name)
About your authentication itself, the problem is that you have to choose between:
Using the bearer token of your application to get an OAuth 2 "App-Only" authentication. You will have, basically, the same possibilies as an unregistered user on the website.
Using an account's tokens to get an OAuth 1.0a "User Context" authentication. You will then be able to act in the behalf of the user who possesses the tokens that you are using.
But you are trying to do both successively.
I put the bearer token with the other parameters in tweepy.Client, it's not separated and works every time:
import tweepy
client = tweepy.Client(bearer_token="YOUR_BEARER_KEY",
consumer_key="YOUR_CONSUMER_KEY",
consumer_secret="YOUR_CONSUMER_SECRET",
access_token="YOUR_ACCESS_TOKEN",
access_token_secret="YOUR_ACCESS_TOKEN_SECRET")
You can also add wait_on_rate_limit=True to limit your rates in case your not handling them properly.
For a simple test similar to Mickaƫl's Answer which prints a twitter username to its respective id:
user_get = client.get_user(username='a_twitter_username_here')
user_id = user_get.data.id
print(user_id)
If this does not work then try regenerating your keys and tokens if you can.
This method does not need elevated access.
I'm attempting to use the Python Firebase Admin SDK to send push notifications for my mobile app. I've tested it with the notification composer in the Firebase Console, so I know my device can receive push notifications, but when I try to use the SDK I never receive anything. Nor do I see the notification listed on the Firebase console notification page.
Here's the exact code(minus my personal info) that I'm using to send the notification:
import firebase_admin
from firebase_admin import credentials, messaging
token = "registration token"
creds = credentials.Certificate('path/to/cert.json')
app = firebase_admin.initialize_app(creds)
msg = messaging.Message(data={'title': 'Test'}, token=token)
print(messaging.send(msg, app=app))
This returns a URL that follows the format /project/<project name>/messages/<message ID> but that URL doesn't work for me. It will just redirect me to the Firebase console base domain and a blank screen. Also, the notifications should be listed under /notifications shouldn't they?
I had had this problem for a week. But it was resolved. Follow these:
Make sure your APNs Certificates or APNs Authentication Key were uploaded in Cloud Messaging settings in Firebase Console
Sure that you use the correct FCM token when sending a firebase.messaging.Message which included apns (messaging.APNSConfig).
Check your AppDelegate.m file was setup following Firebase Docs. In my case, I forgot add [FIRMessaging messaging].APNSToken = deviceToken; in function application:didRegisterForRemoteNotificationsWithDeviceToken:. Keep in mind that the response when you send a message in your server did not say anything about the push notification to your iOS devices even you received a message (it did not contain a notification). And I also don't know how to check whether notification delivered or not.
My python server code:
def push_notification():
title = "Your title"
message = "Your message"
ntf_data = {"key": "value"}
fcm_token = "your_fcm_token"
topic = "your_topic"
# apns
alert = ApsAlert(title = title, body = message)
aps = messaging.Aps(alert = alert, sound = "default")
payload = messaging.APNSPayload(aps)
# message
msg = messaging.Message(
notification = messaging.Notification(
title = title,
body = message
),
data = ntf_data,
token = fcm_token,
topic = topic,
apns = messaging.APNSConfig(payload = payload)
)
# send
res = messaging.send(msg)
And frontend react-native notification listener code:
onNotificationListener = firebase.notifications().onNotification((notification) => {
console.log("received notification:", notification)
}
Feel free to ask if there is any problem in my answer or if you need more information. Happy coding.
The return value is a message ID string, and currently it doesn't point to anything (i.e. not a valid URL). It's just the unique ID that FCM has assigned to your notification, and it indicates the notification has been successfully handed off to FCM for delivery. Also, I believe that notifications sent from the SDK do not appear in the Firebase console. You need an actual client (Android, IOS or web) to test this flow end-to-end.
I'm trying to set up a Twitter app using the Account Activity API, to replace my old set up which used the user streaming endpoint. I want to be able to get DM messages to one user sent to a particular URL in real time.
Following these migration instructions, I've set up a webhook endpoint on my site, as described here. I've checked that process is working, by making sure that when I open https://example.com/webhook_endpoint?crc_token=foo in my browser, I get a token in response.
Now I'm trying and failing to register my webhook. I'm using the following code, and getting a 403 response.
from requests_oauthlib import OAuth1Session
import urllib
CONSUMER_KEY = 'my consumer key'
CONSUMER_SECRET = 'my consumer secret'
ACCESS_TOKEN = 'my access token'
ACCESS_SECRET = 'my access 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://example.com/webhook/')
url = 'https://api.twitter.com/1.1/account_activity/all/env-beta/'
'webhooks.json?url={}'.format(webhook_endpoint)
r = twitter.post(url)
403 response content: {"errors":[{"code":200,"message":"Forbidden."}]}
I can successfully post a status using the same session object and
r = twitter.post('https://api.twitter.com/1.1/statuses/update.json?status=Test')
What am I doing wrong here?
This turned out to be due to a combination of:
Not having created an environment here: https://developer.twitter.com/en/account/environments as described here: https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/guides/getting-started-with-webhooks
using the wrong consumer secret in the function that created the token returned at the /webhook endpoint
I am trying to use the Python library for Coinbase's API, but I receive a 401 error on every request. I tried with a Sandbox account, with a new API key (with every permission) but I get a 401 on every single authenticated request.
Here is my code:
from coinbase.client import Client
client = Client(api_key, api_secret)
client.get_buy_price() # works fine
client.get_accounts() # not working at all
For example, here is a sample with my sandbox key/secret (this pair has full permissions):
from coinbase.client import Client
API_KEY = "b9hXalyQoZ8z4Dk2"
API_SECRET = "fALfigoBfHU6uLcFbWbmPf5NRwgMX9c6"
client = Client(API_KEY, API_SECRET)
print client.get_buy_price() # gets the price correctly
print client.get_accounts() # raises a 401
We had a temporary outage on the API that affected a small number of customers. It should be fixed now.
I am trying to find a way to authenticate and authorize a client to access APIGEE. I can't seem to get it to function. I am using Python Requests-OAuthlib. Here is my code:
from requests_oauthlib import OAuth2Session
client_id = r'my_client_id'
client_secret = r'my_client_secret'
redirect_uri = 'https://api.usergrid.com/org/app'
oauth = OAuth2Session(client_id, redirect_uri=redirect_uri)
authorization_url, state = oauth.authorization_url('https://api.usergrid.com/org/app/token', grant_type='client_credentials')
redirect_response = raw_input(authorization_url)
token = oauth.fetch_token('https://api.usergrid.com/org/app/token', client_secret=client_secret, authorization_response=redirect_response)
url = "https://api.usergrid.com/org/app/my_collection"
r = oauth.get(url)
I get an error: "Please supply either code or authorization_code parameters."
Any ideas on what I am doing wrong? I am using the APIGEE docs found here: http://apigee.com/docs/app-services/content/authenticating-users-and-application-clients
Thank you in advance.
Your client is sending response_type=code in the authorization request. That is why the server is not performing client credential Oauth.
This could be a default behavior of your python client. In that case you might want to use a simple http client to keep things under control.