I am trying to use the drive API to test watching one of my google drive's documents...
I have created a localhost server using python flask...
This is my code for it
from flask import Flask, render_template, request, url_for
app = Flask(__name__)
#app.route('/')
def display():
user = {'nickname': 'Miguel'} # fake user
return '''
<html>
<head>
<title>Home Page</title>
<meta name="google-site-verification" content="XXXX" />
</head>
<body>
<h1>Hello, ''' + user['nickname'] + '''</h1>
</body>
</html>
'''
if __name__=='__main__':
app.run()
#app.route('/hello', METHODS=['POST'])
def hello():
return request.get_data()
I use ngrok to connect my localhost to the internet...
This doesn't even matter however because the drive API cannot connect to the server
as when I use the Google Drive API in the API explorer it gives me
{
"error": {
"errors": [
{
"domain": "global",
"reason": "push.webhookUrlUnauthorized",
"message": "Unauthorized WebHook callback channel: https://44c689c2.ngrok.io"
}
],
"code": 401,
"message": "Unauthorized WebHook callback channel: https://44c689c2.ngrok.io"
}
}
The items that I put into the body are:
{
"address":"https://44c689c2.ngrok.io",
"type":"web_hook",
"id":"abc123"
}
Is there any way to fix this?? Thanks...
You have the same issue in this post.
To use Push Notifications in Google Calendar make sure you
followed the instructions here:
Register the domain of your receiving URL in Google Dev Console. Go to Credentials and click Domain Verification for the webhook setup.
For example, if you plan to use
https://yourdomainexample.com/notifications as your receiving URL,
you need to register https://yourdomainexample.com. Set up your
receiving URL, or "Webhook" callback receiver.
This is an HTTPS server that handles the API notification messages that are triggered when a resource changes.
Set up a notification channel for each resource endpoint you want to watch.
A channel specifies routing information for notification messages. As
part of the channel setup, you identify the specific URL where you
want to receive notifications. Whenever a channel's resource changes,
the Google Calendar API sends a notification message as a POST request
to that URL.
You may also check this this SO thread.
Related
I use django channels 3.0.0 and websocket using angular.
But users connect to django websocket and they are in their own rooms respectively.
And when I want to send the event to connected users outside of consumers, I used the following code.
all_users = list(Member.objects.filter(is_active = True).values_list('id', flat = True))
for user_id in all_users:
async_to_sync(channel_layer.group_send)(
"chat_{}".format(user_id),
{ "type": "tweet_send", "message": "tweet created" }
)
And in consumers.py, my consumer class's chat_message function
async def tweet_send(self, event):
content = event['message']
# Send message to WebSocket
await self.send(text_data=json.dumps({
"type": "MESSAGE",
"data": content
}))
And this "self.send" function is meant to be sent to all connected users respectively, but when I run the code, the all data are sent to only one user who has connected the last time.
I don't know why. If anyone knows the reason, please help me.
This is indeed a bug in version 3.0.0. It was reported and fixed in 3.0.1.
I have a website written on Flask, and I would like to update it when answers to a Google Form has been submitted.
More precisely, I have already associated the form to a Google spreadsheet and I can read that spreadsheet from Flask, but the key component missing is how to trigger the website to update its content when new answers have been submitted to the form.
What would be the best way to do this?
Webhook solution:
Google Forms:
Enter the Google Forms editor
Click 3 vertical dots next to profile picture, and select 'script editor'
Customize this snippet to your WebHook url and set a custom token (this is not really secure, but better than nothing ).
function onFormSubmit(e) {
const url = "https://example.com/webhook";
var options = {
"method": "post",
"headers": {
"Content-Type": "application/json"
},
"payload": JSON.stringify({"token": "sometokenheretocheckonbackend"})
};
UrlFetchApp.fetch(url, options);
}
( Dialog may popup where you have to approve that you connect to an unauthorized service )
Handling on the Flask side:
from http import HTTPStatus
from flask import (
abort,
request
)
#blueprint.route('/webhook', methods=['POST'])
def handle_webhook():
payload = request.get_json()
if payload.get('token') != "sometokenheretocheckonbackend":
abort(HTTPStatus.UNAUTHORIZED)
# Update your content
return jsonify({'success': True}), HTTPStatus.OK
Periodic updates (Alternative solution):
I would consider launching a daemon Thread that periodically updates this content. This is obviously not as elegant, but should work quite stable and wouldn't be much more demanding for the server if the content update procedure is reasonably lightweight.
You could create an Form Submit trigger to trigger a Google Apps Script function that calls out to your Flask site and triggers the update.
https://developers.google.com/apps-script/guides/triggers/installable
I am trying to integrate django-anymail with mailgun. When I send a mail with django send_mail as
send_mail('Testing', 'Test dsadsadsa asdsa body', 'xyz#mailinator.com', ['xxxx#gmail.com'])
It gives an error:
AnymailRequestsAPIError: Sending a message to xxxx#gmail.com from xyz#mailinator.com
ESP API response 404:
{
"message": "Domain not found: mailinator.com"
}
How can I get rid of this?
My settings file contains this:
ANYMAIL = {
"MAILGUN_API_KEY": "key-xxxmyprivatekey",
}
EMAIL_BACKEND = "anymail.backends.mailgun.MailgunBackend"
DEFAULT_FROM_EMAIL = "no-reply#mailinator.com"
It sounds like you have not verified your sending domain in Mailgun. Anymail is reporting the API error directly from your ESP, Mailgun, which is complaining they can't find the domain you're trying to send from.
Sign into your Mailgun account and check the domains list in their dashboard. Is mg.mailinator.com listed there with a green "Active" badge? If not, add it if necessary, and then follow Mailgun's instructions to verify the domain.
Is there some way to send push notifications using Parse and a web service built in Django? I mean, I have a dashboard built in django, in this dashboard I can set it up some parameters, when I create for example a new news, this has to be notified to the user through a push notifications. How can I achieve this?
See that page... https://www.parse.com/docs/rest/guide you should try make a request similar to this....every time you make some news
import json,httplib
connection = httplib.HTTPSConnection('api.parse.com', 443)
connection.connect()
connection.request('POST', '/1/classes/GameScore', json.dumps({
"score": 1337,
"playerName": "Sean Plott",
"cheatMode": False
}), {
"X-Parse-Application-Id": "${APPLICATION_ID}",
"X-Parse-REST-API-Key": "${REST_API_KEY}",
"Content-Type": "application/json"
})
results = json.loads(connection.getresponse().read())
print results
I'm trying to retrieve embedded tweets using statuses/oembed , the url sent to the api is https://api.twitter.com/1.1/statuses/oembed/507185938620219395.json
but i noticed in the documentation the sent url should be
https://api.twitter.com/1.1/statuses/oembed.json?id=507185938620219395
i'm already using search/tweets smoothly, the problem is only with oembed.
Below is a sample of what i'm doing
from twitter import *
class TwitterCrawler(object):
# Authenticate twitter API
# Access token, Access token secret, Consumer key, Consumer secret
def __init__(self):
self.t = Twitter(
auth=OAuth(self.accessToken,
self.accessTokenSecret,
self.consumerKey,
self.consumerSecret)
)
def getEmbeddedTweet(self):
result =self.t.statuses.oembed(id="507185938620219395")
return result
the error returned is:
TwitterHTTPError
Twitter sent status 404 for URL: 1.1/statuses/oembed/567386147631144960.json using parameters:...details: b'{"errors":[{"message":"Sorry, that page does not exist","code":34}]}'
The correct endpoint for this is publish.twitter.com/oembed