I created a demo push notification by:
ionic start pushdemo
Add added the following code in app.js:
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
var push = new Ionic.Push({
"debug": true
});
push.register(function(token) {
console.log("Device token:",token.token);
push.saveToken(token);
});
Add I created push certificate and provisioning profile for iOS and also create an app in google for GCM.
Then I set the dev_push to false in .io-config.json.
I tested for Android by running the app in emulator:
ionic run android -lc
Doing this, I can get the device token. Then I'm able to send push notification by curl command:
curl -X POST -H "Authorization: Bearer xxxxeXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI3NjI4MzUyNi1mZjMxLTRhMGItODAxOC0xZmM2ZTY0ZTA3N2YifQ.xCSZk4vQwKajGQ4TOoWyN5GIPnA14jhYfDRMDrtxxxx" -H "Content-Type: application/json" -d '{ "tokens": ["DEV-67e379b0-0752-424c-9a73-0503ce0ad385"], "profile": "pushdemo_dev", "notification": { "message": "Hello World!!!" }}' "https://api.ionic.io/push/notifications"
I have no problem to receive the push notification when the app is running in foreground. But I'm not able to get the push notification when the app is in background.
The other issue is that the device token is always changed when app restart. Is this normal?
Another problem is I'm not able to get push notification when I push message through Dashboard in ionic.io.
Any idea? Thanks.
EDITED:
When I tested on ios device, I'm able to get the device token something like: 5137fcda 88b7e401 2dc7ac21 e4d80f96 d8702ee6 cd6e08ac 874a0b20 9a9882b0. But I can't get push notification when I used the above mentioned curl command. The returned value is:
{"data": {"created": "2016-06-10T09:17:07.031440+00:00", "config":
{"profile": "pushdemo_dev", "notification": {"message": "Hello World
ios!!!"}, "tokens":
["5137fcda88b7e4012dc7ac21e4d80f96d8702ee6cd6e08ac874a0b209a9882b0"]},
"status": "open", "uuid": "151f86f9-8b09-4e9c-9402-779544dbcbd1",
"state": "enqueued", "app_id": "0dfdafd1"}, "meta": {"version":
"2.0.0-beta.0", "request_id": "99e6891c-4fa5-40a9-a1ec-2fd283905c5f",
"status": 201}}
EDIT 2:
Finally get it works in ios by using Postman to push. The format of device token returned is something like 5137fcda 88b7e401 2dc7ac21 e4d80f96 d8702ee6 cd6e08ac 874a0b20 9a9882b0. But when I post in Postman, I have to remove the space. However there is still a problem, I'm not able to receive push notification when I run the app in foreground. It only shows the push notificaiton when the app is running in background.
my program also doent working on real devices but it isworking on browser it means my io is working fine
and for you dont use dashboard instead use postman it is good
Related
I want to use one signal to send VoIP push notifications to the iPhone. so I created a VoIP push notification and uploaded the p12 certificate to one signal dashboard in postman or curl. When I send a notification, it returns 200 (status success) but no notification is sent to my device. do you have any idea why?
request :
curl --include \
--request POST \
--header "Content-Type: application/json" \
--data-binary "{\"app_id\" : \"xxxxxxxx-xxxx-4a41-ac20-363497c923e5\",
\"identifier\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",
\"language\":\"en\", \"device_type\":0,
\"tags\":{\"FirstName\":\"amir\",\"LastName\":\"tutunchi\",\"Speciality\":\"Yoga\",\"MeetingID\":\"456354646\",\"AppointmentDate\":\"2019-05-29T22:45:47+04:30\",\"AppointmentTitle\":\"check\"}}"\
https://onesignal.com/api/v1/players
response :
{
"success": true,
"id": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx" }
So far REST API get method working in my local ng serve , but in my device not working.
Android device remote debug showing :URL:'localhost/get/list'
proxy.config.json
"/code":{
"target": "http://192.x.x.x:8010",
"secure":false,
"changeOrigin": true,
"logLevel": "debug"
},
Serive Get Method:
this.service.getUrl('/get/list','level=2').subscribe(
data=>{ //Android Device URL :localhost/get/list not showing proxy.config.url
});
package.json
"start": "ng serve --proxy-config proxy.conf.json",
Remote Debug Result:**I can't get **_body result like local result , it's seems getting index.html page.
Local ng Serve Result:
If you are using the emulator and the API is on your local machine, change the IP address in proxy.config.json to 10.0.2.2. Check out How do you connect localhost in the Android emulator?
Following the below steps:
created a new app at https://developers.kite.trade/apps
obtained the <API key> from the app details page
obtained the <API secret> from the app details page
calling an API called holdings API using curl like this:
curl -X GET https://api.kite.trade/portfolio/holdings -H 'Authorization: token <API key>:<API secret>' -H 'X-Kite-Version: 3'
All the steps look correct to me however I'm getting the following error:
{
"status": "error",
"message": "Incorrect `api_key` or `access_token`.",
"data": null,
"error_type": "TokenException"
}
I regenerated the <API secret> 3 times from the app details console.
Now, the question here is not about why I'm getting the error from https://api.kite.trade
The question is whether the authorization header is correct or not?
I have seen many APIs asking for base64 encoded headers so I did that too but the API seems not working.
Is it not the right approach for testing an API?
Try using Postman to test your API request. Also, check what kind of authentication your API is using ( oAuth 2.0, etc). If that's the case, your request headers might look something like this:
{
Authorization: 'Bearer <API token>'
}
I am attempting to POST a file to my Pivotal Tracker instance as specified by the excellent documentation found here.
I continue to get an "uploaded: False" back from the server.
- My token and project id are correct since I can POST new stories etc..
- My file is in place and accessible by the user running this command
fakeuser#fakehost:~/jobs/fakeproject/builds/51$ curl -X POST -H "X-TrackerToken: <mytoken>" -F file=#"/var/lib/jenkins/jobs/changelog.xml" https://www.pivotaltracker.com/services/v5/projects/<projid>/uploads
{
"kind": "file_attachment",
"filename": "changelog.xml",
"created_at": "2013-11-12T14:05:21Z",
"size": 128,
"id": 11111111,
"big_url": "#",
"content_type": "application/xml",
"thumbnail_url": "#",
"uploader_id": 112121212,
"thumbnailable": false,
"download_url": "/file_attachments/1212121212/download",
"uploaded": false
}
I got an email back from Pivotal Labs with an answer to this question. Thanks Pivotal Labs!
Short answer:
It's fine, that "false" is just an indicator that the background job to make that file available to your project hasnt happened yet.
From the email
...
When you upload a file to Tracker, whether via the API or the UI, an
asynchronous job has to run to complete the upload and create the
thumbnail image. So the immediate response to your request reflects
the fact that this job hasn't completed yet. I can see how confusing
this is, though.
...
I've already configured adMob for my Android apps and have no problem with that.
Right now I'm looking for any way to check my apps earnings (if possible for each of the apps separately) in any given moment.
Somebody knows if there's any API, library or Web Service I can use to access my AdMob account and get info about my apps' statistics and so on ?
I've already checked the official APK but it seems only intended to show the ads in your app and nothing else.
Thanks in advance
I answer myself.
I was doing some research, and I found that after the recent changes on AdMob, and the migration to AdSense, you must use the AdSense API to get this info.
In particular, each Android app is associated with a "adunit" id, so if you want to check the info of any particular app you might use:
https://developers.google.com/adsense/management/v1.4/reference/accounts/reports/generate
with the following data:
accountId = your Publisher ID (pub-XXXXXXX)
startDate and endDate = The interval of dates you want to check
dimension = AD_UNIT_ID
metric = EARNINGS
With this query you'll have the required info, separated by App.
You get the results in JSON form.
There is an AdMob API available to get the AdMob specific data.
It provides a possibility to generate network and mediation reports available. It could be as simple as:
curl -X POST https://admob.googleapis.com/v1/accounts/<your_publisher_id>/mediationReport:generate \
-H "Authorization: Bearer <access_token>" \
-H "Content-Type: application/json" \
--data #- << EOF
{
"report_spec": {
"date_range": {
"start_date": {"year": 2020, "month": 4, "day": 1},
"end_date": {"year": 2020, "month": 4, "day": 1}
},
"dimensions": ["AD_SOURCE", "AD_UNIT", "PLATFORM"],
"metrics": ["ESTIMATED_EARNINGS"]
}
}
EOF
.net: https://developers.google.com/api-client-library/dotnet/apis/admob/v1
java: https://github.com/googleapis/google-api-java-client-services/tree/master/clients/google-api-services-admob/v1
Get an Oauth2.0 access token
With oauth2l
install: https://github.com/google/oauth2l
oauth2l header --json <path_to_secret_json> https://www.googleapis.com/auth/admob.report
path_to_secret_json - is one from the credentials page on the google cloud console.
With curl
Replace the oauth2_client_id with the one you have in your “Cloud project credentials - OAuth 2.0 client IDs” page. (https://console.developers.google.com/apis/credentials?project=)
https://accounts.google.com/o/oauth2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadmob.report&response_type=code&client_id=&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob
Open this link in incognito browser mode;
Follow the instruction, and accept the consonant screen with AdMob publisher's account;
Copy the code, it would be needed for the following request:
curl -L \
-d "client_id=<oauth2_client_id>" \
-d "client_secret=<oauth2_secret>" \
-d "grant_type=authorization_code" \
-d "code=<sign_in_code_from_the_previous_step>" \
-d "redirect_uri=urn:ietf:wg:oauth:2.0:oob" \
https://accounts.google.com/o/oauth2/token
oaut2_client_id and oauth2_secret can be found on the OAuth 2.0 client Id page.
Response:
{
"access_token": "<access_token>",
"expires_in": 3600,
"refresh_token": "<refresh_token>",
"scope": "https://www.googleapis.com/auth/admob.report",
"token_type": "Bearer"
}