Set up watch() with Gmail API, Trigger animation in TouchDesigner - python

please pardon my lack of understanding with Python, Gmail API, etc.
I'm trying to set up basic functionality to trigger an animation in TouchDesigner, based off whenever a Gmail account receives a new email.
How and where would I make the following code request?
=========================
request = {
'labelIds': ['INBOX'],
'topicName': 'projects/myproject/topics/mytopic'
}
gmail.users().watch(userId='me', body=request).execute()
========================
I've made a separate python file, and it keeps telling me that "name 'labelIDs' is not defined". Am I not importing the correct libraries? Or should there be more defining at the top of the file? I ca't find any examples/tutorials that explain how to best call the watch() function.
Any help would be greatly appreciated

Related

Creating a Code Challenge for Spotify API PKCE, Why Is It Not In Byte Form?

I am not sure if i can ask about the Spotify API but saw no other subreddit to put in.
I am trying to connect to Spotify API without the use of external packages (like Spotipy).
I am reading their documentation here:
I decided to use the PKCE since I want to distribute a software and the user only needs to give their client_id (its open source)
In that case, I need to create a "code challenge", this is what I have:
SpotifyCodeChallenge = base64.b64encode(hashlib.sha256(SpotifyCodeVerifier.encode()))
Yet this is the error I get:
How would I fix this?
SpotifyCodeChallenge = base64.b64encode(hashlib.sha256(SpotifyCodeVerifier.encode('utf-8')).digest())
This will prob do it.

ast.literal_eval InternalServerError

I'm working with Python for AWS Lambda. I have Profile PATCH and Profile DELETE api calls. PATCH request works fine. DELETE returns InternalServerError on
profile_request = ast.literal_eval(str(event['_body']))
PATCH uses the exact same thing. I even tried copy-pasting the line from PATCH to make sure there wasn't a typo. I've seen people say a syntax issue can cause this. I copy-pasted the body from PATCH and replaced profile with archive_status to make sure there wasn't a syntax issue. event is a dictionary. event['_body'] is unicode type. Both requests have the exact same Authorization and Headers requirements. I checked CloudWatch logs to make sure the body is actually listed as _body in the event. I can't figure out why I am getting the InternalServerError for DELETE profile and not PATCH profile. Any suggestions would be appreciated.
PATCH body:
{
"AccessToken": "eyJraWQiOiIzRUZtNG1lRE45c1wvQU9XUGdiYkZJNm1wakVkOVRFR05PYTY0SXJZOWRDdz0iLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIwZ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NkOGUiLCJkZXZpY2Vfa2V5IjoidXMtZWFzdC0xXzhkYTA3NWQ2LWEzNmItNDZhNS04YjAyLWY3ZmNjY2UxMGZiOCIsInRva2VuX3VzZSI6ImFjY2VzcyIsInNjb3BlIjoiYXdzLmNvZ25pdG8uc2lnbmluLnVzZXIuYWRtaW4iLCJpc3MiOiJodHRwczpcL1wvY29nbml0by1pZHAudXMtZWFzdC0xLmFtYXpvbmF3cy5jb21cL3VzLWVhc3QtMV96dnNGSkYzRzEiLCJleHAiOjE1MDYzNzI2MjksImlhdCI6MTUwNjM2OTAyOSwianRpIjoiMDU3NTkwMzItYmQ5YS00MzljLWJjM2QtYWY2OGZiZjJmNTBiIiwiY2xpZW50X2lkIjoiNWNscm9vNDhtamZpb2QzaDRoZGgyZDNvZHUiLCJ1c2VybmFtZSI6IjBlNDVkNjJmLWZjNDEtNDE1NC1iNmI4LTg2MGI1N2RlY2Q4ZSJ9.G2-gGYyZajrsAikFPuuttYQAj1Yc7uj-UUz469NEUk0SoEFvcJ3E6MOINmIWYg1W6BwJG09W4C_DvBrbybNZep-TtVoAHqNeuiEubt4IABeycZ9ELhKS4G-aaIvbV6CTVFVljFcUdTqCBf0TP7kxKp6P2kRRx08PjCqfQX-34XE-YJt2FyIGzSc958OT0MasROdHxr_ozJS6LGHw52BF1UG1llpR3YPGtMe8Gz9Y65RFEIDIpXllShKSFogvy-rdJFnaJqAYYn6WfjtmqDUjYzFTNZmGNOWy7_BxGFX90lUBB0V47k8M4nxvC_qWQ9o1LTkCYXIDD9sWMCtY4ewYmw",
"archive_status": "archive"
}
Sorry. I'm fairly new to python and brand new to json and AWS. Another company setup chalice for deployment and a skeleton of our api with some basic code. I'm supposed to figure it all out and learn how to make it work as my company wants it to. I was testing through postman. The lambda code logger that goes to cloudwatch was how I was tracking down the issue. It turns out the issue was the log line immediately after ast.literal_eval:
profile_request = ast.literal_eval(str(event['_body']))
logger.info(profile_request)
I assumed not seeing that log in cloudwatch meant the ast.literal_eval was the issue. Finding a way to test locally so I could see the trace allowed me to figure out the log line was causing AttributeError: 'dict' object has no attribute 'strip'. That's an easy one so the problem is resolved. Glad I know how to test locally now also. Thank you for replying so quickly.

Sending an order to oanda

I want to send an order to oanda to make a transaction,I use ipython notebook to compile my code,this is my code:
import oandapy
trade_expire=datetime.now()+timedelta(days=1)
trade_expire=trade_expire.isoformat("T")+"Z"
oanda=oandapy.API(environment='practice',access_token='XXXX....')
account_id=xxxxxxx
response=oanda.create_order(account_id,instrument='USD_EUR',units=1000,side='buy',/
type='limit',price=1.105,expire=trade_expire)
But the error is:
OandaError: OANDA API returned error code 4 (The access token provided does
not allow this request to be made)
How can I solve this problem?
I had the same problem, but when sending orders via curl commands.
The problem has to do with which API you are using from which account.
I notice in your python it says "practice," so you'll want to make sure the API token you generated is from within your practice account. Live accounts and practice accounts each use their own API tokens, and your commands will need to match.
You might also look elsewhere in your python, where it actually pings OandA's server.
For example, when using curl, a live account uses
"https://api-fxtrade.oanda.com/v3/accounts/<ACCOUNT>/orders"
and a practice account uses
"https://api-fxpractice.oanda.com/v3/accounts/<ACCOUNT>/orders"
Using your API token generated on your live account in a practice account will produce the error you're asking about.

How to solve "Insufficient Permission" for userUsageReport with Google API?

I'm trying to write a Python script that will check if a user account has got two-step verification enabled.
As a starting point, I'm using the quickstart script provided on https://developers.google.com/admin-sdk/reports/v1/quickstart/python. I've followed the instructions and the sample code works as expected.
I then add the following line after the example code:
results = service.userUsageReport().get(userKey='john.doe#example.com', date='2016-08-02', parameters='accounts:is_2sv_enrolled').execute()
but I get "Insufficient Permission" returned.
Just to make it clear, I do replace "john.doe#example.com" with an email address that is valid for my organisation :).
I've double-checked the credentials used and, indeed, if I use the web-based API Explorer with the same account being used to run the script, it works.
I don't understand why the call to activities().list() is working but userUsageReport().get() isn't.
I've solved this.
userUsageReport requires the usage scope to be added, specifically:
https://www.googleapis.com/auth/admin.reports.usage.readonly
Since the quickstart only reference the audit scope:
https://www.googleapis.com/auth/admin.reports.audit.readonly
that is why I was getting the error.

Implementing Reset Password and Email Changes in Google Identity Toolkit

I'm currently working on a python-based app engine website and am looking to add google identity toolkit functionality but am getting stuck on the implementation of password resets and changes to email address..
Have been able to get the python quickstart example (https://developers.google.com/identity/toolkit/web/quickstart/python) working properly but even using this, I haven't been able to properly set up the password reset and email change components
I've been going through the google groups for this at https://groups.google.com/forum/#!forum/google-identity-toolkit but can't seem to be able to find detailed steps or sample code based off python
Would anybody have any ideas or can point me in the right direction? Much appreciated!
After some trial and error, I've been able to get this to work by:
creating a gitkit instance using the gitkit server config json
calling the GetOobResult function, which sends back a dict containing the reset link, among other information (This is the crux)
finally, to get the user notification to work properly you'll need to return a json dump with {'success' : true}
Here are the key lines of code I used -- should note that this doesn't include the email sending portion with the password reset link, which you have to implement separate from gitkit..
server_config_json = os.path.join(os.path.dirname(__file__), 'gitkit-server-config.json')
gitkit_instance = gitkitclient.GitkitClient.FromConfigFile(server_config_json)
output = gitkit_instance.GetOobResult(self.request.POST,self.request.remote_addr)
if output:
self.response.headers['Content-Type'] = 'application/json'
self.response.out.write(json.dumps({'success': True} ))

Categories

Resources