I raise a subscription request as below and the response is:
Subscription validation request failed. Must respond with 200 OK to this request.
Ho do I do I send this response please in UWP?
var result = await request.AddAsync(
new Subscription
{
ChangeType = "created,updated",
NotificationUrl = "https://webhook.azurewebsites.net/notificationClient",
Resource = "/me/mailfolders('inbox')/messages",
ExpirationDateTime = DateTimeOffset.Now.AddMinutes(20),
ClientState = Guid.NewGuid().ToString()
}
);
Ok, I think i need the webhook and the notificationClient, how/ where do i get these values?
Graph webhooks are not possible on UWP, at this time streaming notifications should be used from the outlook 365 api.
Related
I'm trying to receive watch notification for Gmail mailboxes in my .NET C# program.
I have the following code:
WatchRequest body = new WatchRequest()
{
LabelIds = labelIds,
TopicName = PrivateKeys.GoogleGmailTopic
};
WatchResponse response = new UsersResource.WatchRequest(_gmailService, body, "me")
{
Key = PrivateKeys.GoogleApiKey,
OauthToken = AccessToken
}
.Execute();
... and it seems to work, since I get a response.
But where do I receive these notifications inside my program? How can I configure the event entry point?
Assuming you did the preliminary work to set up a Cloud Pub/Sub client (described here: https://developers.google.com/gmail/api/guides/push#initial_cloud_pubsub_setup), you should have a Pub/Sub subscription - either PULL or PUSH.
In order to get the notifications, your application should initiate a subscriber, you can follow the instructions in https://cloud.google.com/pubsub/docs/pull for PULL or in https://cloud.google.com/pubsub/docs/push for PUSH. Configuring the event entry point should be done as part of the subscriber set up.
I want to get an email from my gmail sent items via c#.
I used this
service.Users.Messages.Get("me",id);
but it get 404 error.
All other apis works properly.
Thanks.
404 means that the Id you are requesting does not exist. I would run a List first then a get after.
If you want to see messages that are in the sent folder you should do a message.list
and search for what is in the sent folder.
var request = service.Users.Messages.List("me");
request.Q = "is:sent";
var result = request.Execute();
If you know when it was sent you could add a date.
var request = service.Users.Messages.List("me");
request.Q = "is:sent after:2021/3/28 before:2021/3/31";
var result = request.Execute();
Tip Q works just like the search function in the Gmail web application so if you can get that to return what you want just add it to Q
I have the following functions to get messages using Graph API
var client = new GraphServiceClient(authenticationProvider);
var messages = await client.Users["useer#domain.com"].Messages
.Request()
.GetAsync();
I am only able to get the latest 10 messages. How do I get all the messages? I tried to have a look at the microsoft documentation here: https://learn.microsoft.com/en-us/graph/api/message-get?view=graph-rest-1.0&tabs=csharp but unable to find any clues.
Found the answer after googling and trial error.
IUserMessagesCollectionPage msgs = await _client.Users[user#domain.com].Messages.Request()
.Filter("put your filter here")
.GetAsync();
List<Message> messages = new List<Message>();
messages.AddRange(msgs.CurrentPage);
while (msgs.NextPageRequest != null)
{
msgs = await msgs.NextPageRequest.GetAsync();
messages.AddRange(msgs.CurrentPage);
}
You can do it with .Top():
var client = new GraphServiceClient(authenticationProvider);
var messages = await client.Users["user#domain.com"].Messages
.Request()
.Top(100)
.GetAsync();
I think you should refer to this document:
Depending on the page size and mailbox data, getting messages from a mailbox can incur multiple requests. The default page size is 10 messages. To get the next page of messages, simply apply the entire URL returned in #odata.nextLink to the next get-messages request. This URL includes any query parameters you may have specified in the initial request.
I have a c# project sending firebase messages via http post to clients having ios and android.
When clients uninstall my app their firebase device IDs are not deleted from my database unfortunately.
The next time I send a message to the device id witch corresponds to an user who uninstalled my app, of course the message is not delivered.
Is there any way to know if the message was not delivered ?
Unfortunately the response is always successful even if the message is not delivered.
My current code:
var firebaseMessage = new FirebaseMessage();
firebaseMessage.data = notificationMessages;
firebaseMessage.to = device.DeviceRegistrationId; <-- maybe this device is no longer valid
firebaseMessage.priority = "high";
firebaseMessage.notification = new ExpandoObject();
firebaseMessage.notification.title = "myApp";
firebaseMessage.notification.body = "testMessage";
firebaseMessage.notification.sound = "default";
firebaseMessage.notification.click_action = "FCM_PLUGIN_ACTIVITY";
firebaseMessage.notification.icon = "fcm_push_icon";
firebaseMessage.notification.delivery_receipt_requested= true;
var client = new HttpClient();
var appKey = "key=" + ApplicationConfig.FirebasKey;
client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", appKey);
var response = await client.PostAsJsonAsync("https://fcm.googleapis.com/fcm/send", message);
return response;
When your app is uninstalled from a device, the corresponding registration token would then be invalidated by the FCM server, so any messages sent to that specific token would result to a NotRegistered response (also see my post here). In that event, you could proceed with deleting the token (or archiving it).
If your use-case intentionally wants to know if the message was received on the client side, you're gonna have to implement Delivery receipts.
I've been trying to set up PayPal Webhooks (in Sandbox mode) to receive notifications about declined and successful payments. My problem is that I can't get validation working. Some details about my attempts:
The app is an OWIN self-hosted Web API 2.
Hosted as an Azure Web App, tested on Azure as well.
I set the Paypal Webhook receiver URL in the Paypal dashboard to the URL of my endpoint on Azure.
I used the Paypal Webhooks simulator from the Paypal dashboard to send a message to the Azure endpoint.
I tried listening for Webhook calls two ways:
ASP.NET Webhook Receivers (http://blogs.msdn.com/b/webdev/archive/2015/09/04/introducing-microsoft-asp-net-webhooks-preview.aspx), which didn't work. I get the error message "WebHook validation failed: "
Tried creating a Web API endpoint to receive and validate the request, didn't work either. Code here:
[HttpPost]
public async Task<IHttpActionResult> PaymentCaptureCompleted()
{
// Get the received request's headers
NameValueCollection nvc = new NameValueCollection();
foreach (var item in Request.Headers)
{
nvc.Add(item.Key, string.Join(",", item.Value));
}
// Get the received request's body
var requestBody = await Request.Content.ReadAsStringAsync();
var isValid = WebhookEvent.ValidateReceivedEvent(Api, nvc, requestBody, ConfigurationManager.AppSettings["paypal.webhook.id"]);
if (isValid)
{
return Ok();
}
else
{
return BadRequest("Could not validate request");
}
}
There are a lot more details to this of course, but I'm not sure how much information is required to answer my question. Just let me know what you need and I'll edit this question.
Please refer PayPal Dot Net SDK for code samples. https://github.com/paypal/PayPal-NET-SDK
Also if your simulator is not working, to rule out if there is something wrong with the configuration of webhook or the azure, you may want to use Runscope. Ypu can configure a Runscope bucket as a webhook endpoint and If you are getting a webhook notification there, you may need to make changes in the Azure config.
Really don`t go to the documentation. It is old but objects is still good.
You can use WebhookEvent class for it.
Just use this action in your controller.
public JsonResult Index(WebhookEvent event)
{
// event has all the data
return Json(new { success = true });
}
Validation does not work for either IPN sandbox nor Webhook events from the mock. It's stated in the PayPal documentation. Validation only works on the production environment of PayPal.
Wrap WebhookEvent.ValidateReceivedEvent in a try catch. If the call fails, it can just hang without that. The exception will show you the error.
try
{
var isValid = WebhookEvent.ValidateReceivedEvent(apiContext, nv, requestBody, hookId);
}
catch(Exception e)
{
}
In my case the exception said "Unable to load trusted certificate"