Graph API Subscription Notification Fires Continuously - onedrive

I am creating subscriptions to a OneDrive folder using the Graph API and I am receiving change notifications continuously (every half a second) even when the contents of the folder (or even the drive itself) is not changing. (Obviously I was expecting that I would receive notifications only when the folder contents change).
I post the following JSON to create the subscription:-
{
"clientState": "GraphAPITest1 2018/05/01 11:31:26",
"notificationUrl": "https://123e7ff5.ngrok.io/notification/listen",
"resource": "/drives/b!X5kF-EHEkECCcjyJ3Fh1CTQI-5nOBktJv57zZdpp13CPQb_8FIV-RIPt-7fnzyxP/root",
"expirationDateTime": "2018-05-02T11:31:26.0881202+01:00",
"changeType": "updated"
}
The notification that my service receives is:-
{
"value": [
{
"subscriptionId": "2467af01-a616-4493-8947-220146c4828a",
"clientState": "GraphAPITest1 2018/05/01 11:23:13",
"resource": "/drives/b!X5kF-EHEkECCcjyJ3Fh1CTQI-5nOBktJv57zZdpp13CPQb_8FIV-RIPt-7fnzyxP/root",
"resourceData": null,
"changeType": "updated",
"subscriptionExpirationDateTime": "2018-05-02T10:23:13.3640899+00:00"
}
]
}
I get the same behaviour in my own code as well as in Microsoft's example app (https://github.com/OneDrive/onedrive-webhooks-aspnet). My code uses an app-only authentication token but the Microsoft example forces user authentication - both suffer from the same behaviour.
Any idea what I need to do to only get notifications when the contents of the folder actually changes?
Barry

Related

How do I fix the problem behind "THIRD_PARTY_AUTH_ERROR" when using Google's API Explorer to send a Firebase Cloud Messaging message?

I am trying to create a very simple Web app that can send and receive messages (including Push notifications) via Firebase Cloud Messaging. I want to try testing the ability to receive test messages sent from the Google API Explorer. However, I am running into a curious error as just about any API call from the relevant API URL will return the following error:
{
"error": {
"code": 401,
"message": "Auth error from APNS or Web Push Service",
"status": "UNAUTHENTICATED",
"details": [
{
"#type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode": "THIRD_PARTY_AUTH_ERROR"
}
]
}
}
For reference, here is the message that I am trying to send:
{
"message": {
"token": "[FCM_TOKEN]",
"notification": {
"title": "New Notification",
"body": "Sample Text"
}
}
}
I also note that when I add "validate_only": true to the message, that the error goes away and the send request succeeds (though this is of no help, as that disables actually sending the message).
I am stumped, becuse the hint that pops up suggests that my OAuth2 credentials are invalid, though I leave the OAuth2 credential option checked and go through the authorization popup to provide my credentials.
Are you running the web app on Firefox, perhaps?
I have been running around my tail with this same issue for days now, and today I've found that there is an issue on Firefox, while this does work on Chrome:
Similar stack overflow question
The issue on the Firebase repository on Github
Although not a proper answer, I hope this helps.

What are these media providers in whatsapp apis?

I have setup a two way communication between business account and customer using whatsapp business apis. I am having trouble understanding media providers that there documentation talks about for sending text message to customer with image/media.
Heres the link to it: https://developers.facebook.com/docs/whatsapp/api/settings/media-providers/
Who are these providers? are they some specified organisation?
I am currently storing the media files in AWS S3 using some pre-signed url method. Can I use media stored in S3 in whatsapp media message?.
An example would be great help.
According to the Whatsapp API media messages documentation, there are two ways of sending an image outbound message:
Send the image by its Media ID
Send the image by its URL
When choosing 2, sending it by its URL, sometimes you may need to setup a Media Provider settings if the images URL you reference is not directly accessible and requires a username/password authentication or even a bearer token. (check https://developers.facebook.com/docs/whatsapp/api/messages).
Sending images by Media ID
To send it by ID, you need first to upload the image file using the POST /v1/media endpoint. That will return the Media-ID (e.g: 456) that you should use to compose the message object on the POST /v1/messages/ endpoint, like this:
{
"to": "1234567",
"type": "image",
"recipient_type": "individual",
"image": {
"caption": "The image caption",
"id": "456"
}
}
Sending images by URL
When sending it by URL, you can simply inform the URL of a image file (e.g.: http://yourcompany.com/images/your_image.png) on the link field of the POST /v1/messages/ endpoint, just like this:
{
"to": "1234567",
"type": "image",
"recipient_type": "individual",
"image": {
"caption": "The image caption",
"link": "http://yourcompany.com/images/your_image.png"
}
}
What if the URL http://yourcompany.com/images/your_image.png is behind some authentication on the server? (username/password ou maybe a bearer token). Then you need first to setup a Media Provider with such credentials, using the POST /v1/settings/application/media/providers endpoint, like this:
[{
"name": "yourcompany-images",
"type": "www",
"config": {
"basic": {
"username": "the-username",
"password": "the-password"
}
}
}
]
Once you have this set up on your API, then you are able to reference this Media Provider by its name on the POST /v1/messages/ endpoint, like this:
{
"to": "1234567",
"type": "image",
"recipient_type": "individual",
"image": {
"caption": "The image caption",
"link": "http://yourcompany.com/images/your_image.png"
"provider": {
"name" : "yourcompany-images"
}
}
}
Using S3 pre-signed URLs as image links
You have to consider that pre-signed URLs are temporary links that will expire after a while. It can work when everything is fine with you Whatsapp API Client and the message is promptly received by the recipient. But if something goes wrong on this chain, maybe the Whatsapp API will try to download the image again later. So keep this in mind and try to create pre-signed URLs with long expiration time (maybe a 7 day expiration link using IAM User as explained here).

Google Assistant - Account linking with Google Sign-In

I have an Express app which supports Google authentication and authorization via passport. I have begun integrating it with Google Assistant and things were going quite well but I am having trouble with the account linking as described at https://developers.google.com/actions/identity/google-sign-in#start_the_authentication_flow
Using the method in the docs at https://codelabs.developers.google.com/codelabs/actions-2/#4 I was able to get user details but when I try to modify to support
app.intent('Start Signin', conv => {
conv.ask(new SignIn('To get your account details'))
})
and
app.intent('Get Signin', (conv, params, signin) => { ...}
the dialogflow always falls back to my default fallback intent and I get an error in Express console
Error: Dialogflow IntentHandler not found for intent: Default Fallback Intent
My dialogflow intent is set to use webhook and other intents work fine (until I add these sign-in intents!)
Reading this thread Dialogflow IntentHandler not found for intent: myIntent (Dialogflow V2) it was suggested that the intent name rather than the action name is used so I check my Actions on Google simulator and the request contains:
"inputs": [
{
"intent": "actions.intent.SIGN_IN",
"rawInputs": [
{
"inputType": "KEYBOARD"
}
],
"arguments": [
{
"name": "SIGN_IN",
"extension": {
"#type": "type.googleapis.com/google.actions.v2.SignInValue",
"status": "OK"
}
}
]
}
],
so I tried updating my Dialogflow intent name to actions.intent.SIGN_IN and modifying the intent name in my Express app accordingly but it doesn't make any difference.
The simulator response includes:
"responseMetadata": {
"status": {
"code": 14,
"message": "Webhook error (206)"
},
but I'm not sure if that is just because for some reason the intent names are not matching up. Any help much appreciated!
As you speculate in the comments, the issue is that your "Get Signin" Intent isn't registered to get the event indicating that the user has signed in (or failed to). Since there is no such Intent setup, it ends up calling the Fallback Intent, which apparently doesn't have an Intent Handler registered in your webhook.
To make your "Get Signin" Intent get the sign-in event, set the "Event" field to actions_intent_SIGN_IN. (Note the similarity to the Intent name you saw in the simulator, but using underscores instead of dots.)
As an aside, the simulator was showing you what the communication between the Assistant and Dialogflow looks like, so it can be somewhat confusing to understand what Dialogflow is doing with it. It didn't have anything to do with the name of your Intent or anything else.
Finally, it often isn't necessary to do this check. You will know if the user is signed in because either the auth token has been set or the id token has been set (depending on your method of Account Linking).

Automatic tests of click events

Clicks on certain DOM elements sents click events to Google Analytics, as URL requests like https://stats.g.doubleclick.net/r/collect?v=1&aip=1&t=dc&_r=3&tid=UA-1234567-2&cid=297722160.1523959944&jid=2028321276&_gid=1320758195.1530624077&gjid=12698493&_v=j68&z=1135539045
What tools/methods/workarounds are usual to automatically test click events - mainly their status code and content?
I am not 100% sure that I understand your question. First think you should understand is that hits sent to google analytics are not validated they are send and forget. Google analytics returns a gif thats it there is no way to know if the request was a success or a fail.
There is one way of debugging hits being sent to Google analytics in test before you actually release to production and thats the debug endpoint
https://www.google-analytics.com/debug/collect?v=1&aip=1&t=dc&_r=3&tid=UA-1234567-2&cid=297722160.1523959944&jid=2028321276&_gid=1320758195.1530624077&gjid=12698493&_v=j68&z=1135539045
sending your hit to the debug endpoint results in
{
"hitParsingResult": [ {
"valid": true,
"parserMessage": [ {
"messageType": "INFO",
"description": "IP Address from this hit was anonymized to 185.128.103.0.",
"messageCode": "VALUE_MODIFIED"
} ],
"hit": "/debug/collect?v=1\u0026aip=1\u0026t=dc\u0026_r=3\u0026tid=UA-1234567-2\u0026cid=297722160.1523959944\u0026jid=2028321276\u0026_gid=1320758195.1530624077\u0026gjid=12698493\u0026_v=j68\u0026z=1135539045"
} ],
"parserMessage": [ {
"messageType": "INFO",
"description": "Found 1 hit in the request."
} ]
}
This hit was not actually sent to google analytics it was just test sent. If you want to set up some kind of unit testing or atuomation testing of your hits your going to have to do that yourself using the debug endpoint
More info can be found here validating-hits

Can we receive step data in the pub sub payload?

I can see in the payload JSON that the pubsub notification includes the events but is it also capable of sending the activity or sleep amounts (e.g steps or sleep minutes)?
No, the pubsub notification will only include the user and the list of events that took place. You can then use this information to query the APIs that pertain to those specific types of events.
For example, suppose you receive the following pubsub notification:
{
"notification_timestamp": "1372787949",
"events": [
{
"user_xid": "RGaCBFg9CsB83FsEcMY44A",
"event_xid": "EJpCkyAtwoO0XTdkYyuTNw",
"type": "move",
"action": "creation" ,
"timestamp": "1372787849"
},
{
"user_xid": "RGaCBFg9CsB83FsEcMY44A",
"event_xid": "blaHyAtwoO0XTdkYyuTNw",
"type": "sleep",
"action": "updation" ,
"timestamp": "1372787859"
}
],
"secret_hash": "e570b3071a0964f9e2e69d13nd9ba19535392aaa",
}
Then you know that a move event was created and that a sleep event was updated for the user specified by user_xid: RGaCBFg9CsB83FsEcMY44A
Use this user's xid to determine which previously saved access_token to send with your next API requests.
You can get the details for the move event by sending a request to the moves endpoint with the event_xid: EJpCkyAtwoO0XTdkYyuTNw:
GET https://jawbone.com/nudge/api/v.1.1/moves/EJpCkyAtwoO0XTdkYyuTNw
And yo ucan get the details for the sleep event by querying the sleeps endpoint with the event_xid: blaHyAtwoO0XTdkYyuTN:
GET https://jawbone.com/nudge/api/v.1.1/sleeps/blaHyAtwoO0XTdkYyuTN