CURL request for AZURE Push Notification is not working - php

I have gone through links that provide some CURL request samples for AZURE push notifications but none of them works for me.
Like in this url CURL request using Ruby language is provided but like others it is also not working.
"Internal Server Error (500)"
occurred every time when I made a request using CURL requests.
If anybody can provide me with working code of CURL request for AZURE push notifications then it would be convenient for me to solve the issue. Keeping in mind that push notifications from web portal of AZURE are working absolutely fine.

May I know whether you are using Azure Service Bus Notification Hub? If so, the most likely problem from my experience is you may haven't formatted the request properly. It’s needed to prepare the following information, and send them in request headers:
Content-Type: Based on the platform you choose, the value will be different. For instance, for Windows Store apps, content type is application/xml.
ServiceBusNotification-Format: The device type, such as windows.
X-WNS-Type: Push notification type, such as wns/toast.
Authorization: The rules are described in https://msdn.microsoft.com/en-us/library/azure/dn495627.aspx. Pay special attention to the Create SAS Security Token part.
And the request content. The format is different for different devices. For example, for Windows Store apps, it’s needed to use xml like:
<?xml version="1.0" encoding="utf-16"?><toast><visual><binding template="ToastText01"><text id="1">Hello!</text></binding></visual></toast>
If you're using CURL command line, please make sure to use double quotes instead of single quotes.
Also please make sure you have correctly registered the push notification service provider in Azure. For instance, for Windows Store apps, please register the SID and the client secret.
If the issue is still encountered, please share more information. It would be better if you can let us know:
• Are you trying to use the CURL command line or PHP code?
• What kind of device you're using?
• What kind of message you want to send?

Related

Translation using Microsoft Translator API Timeout

I am willing to translate a particular text in 3 different languages using using Microsoft Translator API. I configured it and, apparently, the link I get which should drive me to translation breaks:
https://api.datamarket.azure.com/Data.ashx/Bing/MicrosoftTranslator/v1/Translate?Text=%27Osteopathy%27&From=%27en%27&To=%27nl%27&$format=Raw&$top=100
I tried it also in my terminal with curl, with authorization, but it seems that no response is sent:
$ curl -H 'Authorization: Basic ***my authorization_key encoded in base64***' 'https://api.datamarket.azure.com/Data.ashx/Bing /MicrosoftTranslator/v1/Translate?Text=%27Osteopathy+for+Babies%27&From=%27en%27&To=%27nl%27&$format=Raw&$top=100'
The response from Microsoft Translator doesn't come. It simply times out.
The same piece of code worked few weeks ago.
What could be the cause? How to fix this?
I tried the same request as you and I do get a response back from the server but it's a 403 forbidden. I can't speculate on why the code no longer works but if you also get back a 403 it might be worth refreshing the key, it might have expired somehow. Otherwise the behaviour of the API has changed in a breaking way, it's hard to say without any official documentation.
However, you could try the Microsoft Cognitive Services API, it took be about 5 mins to setup. You will need to use OAuth bearer tokens instead of basic auth, but this is more secure anyway.
Setup docs
https://www.microsoft.com/en-us/translator/getstarted.aspx
Getting a token
http://docs.microsofttranslator.com/oauth-token.html
And some code samples
on github under MicrosoftTranslator/HTTP-Code-Samples
Azure Datamarket has been closed - there is more information here about moving to Azure:
https://translatorbusiness.uservoice.com/knowledgebase/articles/1078534-action-required-before-april-30-2017-microsoft-t

Setting Up Server in PHP and Android to get push notification with the new json-services JSON

I am planning to use Google Cloud Messaging to send push-notifications from my web server whenever something is triggered from the server (PHP). As I read the Google Cloud Messaging just lately has the google-services.json which needed to be moved to the app/ in the Android project. Now, from the tutorial I've tried to look none are using the google-services.json yet. The documentation is pretty explanatory but I still haven't got the clear mind of setting PHP server to send from the server not the Android java program..
Would there be any link or reference related to the topic I asked?
Should I follow the tutorials out there without using the lastest API or what should I'd be recommended do?
Thank you, any help would really be appreciated as I also continue to find out.
You could follow the official GCM demo for the client side. For the server side, you could do your curl calls, taking into account the required headers and properties. If you look at the Java program that acts as a sender, it simply makes HTTP requests.
Older tutorials will unfortunately have differences, such as the URL to send to and the JSON content.

Webhooks on localhost

I am creating a payment gateway using Paymill (which is comparable to Stripe). I want my website to automatically react to subscription-based billings. This is why I am considering Paymill webhooks.
I am in the testing phase and thus on localhost (XAMPP). The receiving webhook script would therefore have this URL:
localhost/paymill-example-php-subscriptions-master/src/Paymill/LlamaKisses/Controllers/WebhooksController.php.
But is it possible at all to set a localhost address as a webhook url (and how)?
(By the way, isn't WebhooksController.php missing a response code line like this:
http_response_code(200);
to let the sending webhook know it succeeded and needn't retry?)
Many thanks in advance!
Use one of these tunneling apps:
http://john-sheehan.com/blog/a-survey-of-the-localhost-proxying-landscape
You can use Webhook Relay (https://webhookrelay.com) to create webhook forwarding tunnels or bidirectional tunnels:
$ relay forward -b webhook-demo http://localhost:8090/webhook
Forwarding:
https://my.webhookrelay.com/v1/webhooks/5e722a5e-f3d2-4hqec-9e9f-79f1158e4b10 -> http://localhost:8090/webhook
starting webhook relay agent..
Endpoints are permanent (until you delete them) and it is also possible to fan-out webhooks to more than one destination.
.
I am using Azure Websites with a Free mode website. With that you can attach remote debugger to the Azure Website and if I am not mistaken you can do that with free tools from MS too. You can easily switch on tracing to Azure Table storage or file system and from within a webbrowser or tools look at logs. It may not be apt for you, but if you have a bit of time to play around it's quite easy. I am logging the whole PayMill webhook message to an Azure Table .

Communicate Android with WebApp - Receive orders by php

I have to make an application that receives commands from a website and therefore perform an action.
I thought about creating a login in android to send the username and password for POST and if this is correct, the web server will return a unique token. That would serve me later to send information to the server and ensure authentication...
But ... how can my android application know when the website has a warrant for?
I've thought about that all the time is pending a URL "checkOrders" and if it finds your token, request orders to another URL
Anybody know other method to make it?
If I understood your question correctly, the only (battery and otherwise) efficient way is using push notifications. Unfortunately, this approach is not even close to being simple.
Since you're developing an Android application, you may want to consider Google Cloud Messaging and Parse Push. If you're planing on developing apps for iOS and Windows phones in the future, I'd strongly recommend Parse Push. At the moment, it's free for up to one million users.
Hyperlink for GCM will lead you to generally useful reading on this topic. That's why I am not elaborating here.

C2DM and PHP Server

I'm trying to write the server side of my android app that uses C2DM. I'm going to write it in php. I basically am just doing tests right now. I copied the chrome to phone example for the actual android app and modified it to my liking. Right now my biggest question is the registration.
Let me get everything straightened out.
When registering the device for the first time, the app talks directly to my server. The server grabs the deviceid and responds back with a 200. Right?
So, on the php side of things, I grab the device id like $deviceid = $_POST['deviceId'] Right?
add it to my database. then respond back to the app.. How exactly do I send a particular response back? I assume in the header? I'm unsure how to do that.
Please confirm or deny that I'm on the right track and clear up any confusion.
Thanks for the help.
You don't respond back to the app. You must register your server with google's servers to get a server authentication token. You then use that server token and the device token in a post request to google's C2DM service to have google's servers send a push notification to the phone. Your app and your server never directly communicate when a push notification is sent in C2DM, it is all done through google, yet you need to implement a mechanism for your server to know the device id of the device it wants to send a message to.
This is a pretty detailed guide, though the server code is in Java:
www.vogella.de/articles/AndroidCloudToDeviceMessaging/article.html
Make sure you have really gotten the IDs before sending to the server. If you are using an emulator for testing, you could do an echo over at the php script so the message will appear in your logcat.
Google refreshes expired registration IDs so your application should be able to pick up new notifications/ids from google and handle the message by sending to the database.

Categories