What is the restful API url to remove a token from a topic? I know that the POST api call to add a token to a topic is like the following:
https://iid.googleapis.com/iid/v1/{token}/rel/topics/{topicName}
Documentation is less than helpful when I want a simple list of restful endpoints that I can use from my server. Thanks.
Given that this is a REST API, so I'd expect a DELETE request to the same URL should work.
But I admit that the documentation is not very clear on this, so please report back if it works (or doesn't).
Google support got back to me. POST'ing to a batchRemove did the trick, per documentation.
https://iid.googleapis.com/iid/v1:batchRemove
Just confirming, that in order to unsubscribe from a topic you have to use
method DELETE:
fetch('https://iid.googleapis.com/iid/v1/'+tokenz+'/rel/topics/movies', {
method: 'DELETE',
headers: new Headers({
'Authorization': 'key=****'
})
If you are using PHP and curl instead of
curl_setopt( $ch, CURLOPT_POST, true ); you must use curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
Related
I am using react-native-mapbox-gl in my react-native app. I want to send a feature request to WMS server. In openlayer I found a solution
MyLayer.getSource()
.getGetFeatureInfoUrl(
evt.coordinate,
map.getView().getResolution(),
map.getView().getProjection(),
{
'INFO_FORMAT': 'application/json',
'propertyName': 'OBJECTID,HOUSE_NUM'
}
);
This creates an URL of feature request. Is there any alternative method for "getGetFeatureInfoUrl" in mapbox-gl. Example will be very helpful.
There is no direct support for constructing a GetFeatureInfo request in Mapbox-GL-JS. You will need to construct it yourself, and make your own HTTP request.
We are sending about 1 lac email daily using sendgrid API.
But what happen is thousand of mail are undelievered to the recipient.
we want to get the list of these undelievered mail. How is that possible ?
Please suggest some idea or links. becouse I am lost and would really appreciate the assistance.
Thank you.
wow..! finally i made it...
curl code-
curl -X GET
https://sendgrid.com/api/bounces.get.json?api_user=undefined&api_key=XXXXXXXX
and here is my the php code
$ch =curl_init('https://sendgrid.com/api/bounces.get.jsonapi_user=10timeslocal&api_key=10timeslocal');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
Thanks a lot to everyone tried to solve this.
I'd start with reading the API docs for bounces, blocks, invalid emails, and spam reports.
You can also consume SendGrid's Event Webhook which will send you post requests with the information you are looking for.
have a table in the database, that must contains the log of all emails send to users. then later fetch status of these emails via sendgrid apis. then update their status as success, bounce, invalid.
then for next time don't send emails to that persons whose status in your list are bounce or invalid.
this way you can avoid sending emails to bounces or invalid users.
I am new to backbone.js. I built a rest api with php and I want to connect to it with backbone.js. I am having a tough time with passing the http basic auth that my rest api uses for authentication.
I can access my rest api easily by using curl from the command line like this
curl -u username:password -X GET http://api.mysite.com/user
But when I try to do a fetch (which is pretty much all I am trying to do) I get a response from my rest api that the authentication failed.
Here is my call from backbone.js
user.fetch({headers:{'Authorization':'Basic username:password'}});
With backbone.js I am getting back the response I would expect when the basic auth fails. My question is, since I know my rest api with authenticate with curl, why won't it authenticate with the above javascript?
Also, when I look at the headers sent in the js console I don't see anything about Authorization.
UPDATE
I tried the plugin listed in the comment below but got the same result
Here is my code
var User=Backbone.Model.extend({
url: 'http://api.mysite.com/user'
});
var user=new User();
user.credentials = {
username: 'username',
password: 'password'
};
user.fetch();
The username and password need to be encoded with Baes64 before being sent.
One easy way to do this (at least for testing) is to configure all jQuery ajax requests to send the info (Backbone uses jQuery for the ajax calls):
$.ajaxSetup(
beforeSend: function(xhr){
xhr.setRequestHeader("Authorization", "Basic " + btoa("USERNAME" + ":" + "PASSWORD"));
}
);
Note that btoa is the function that will encode the params with Base64. Now you can call user.fetch() and it should work properly: you don't need to provide the credentials, because we've configured jQuery to send them for us (all the time).
Of course, depending on your situation (e.g. using multiple APIs), you might prefer to specify the beforeSend attribute within each request, or have it defined within a Backbone syncfunction.
I added "Authorization" to the allowed headers list and that did the trick.
header("Access-Control-Allow-Headers: Authorization, Origin, X-Requested-With, Content-Type, Accept");
I have been using FB api for some simple demo and everything was quite easy with the authentication. Now I have to do something similar with twitter v1.1 but there is something that I really don't understand...
Example:
I want to do this request:
https://api.twitter.com/1.1/search/tweets.json?q=q=%23freebandnames
the problem is that I have to be authenticated, anyone have some examples? I don't want to create a twitter connection because I don't need different users to be connected to my applicaiton. I have just to perform some simple search request but I can't understand how to use the authentication parameters. Which type of Ajax request I have to use in order to perform the REST request authenticated??? (Obviously I have my secret token and my access secret token) but how to use them????
THanks in advance for answers
You can use this javascript library: codebird-js with the "Application-only auth".
or
Do it yourself: everything is explained in the documentation.
Basically you need to follow 3 steps (and you should do the 2 first just once):
An application encodes its consumer key and secret into a specially encoded set of credentials.
An application makes a request to the POST oauth2/token endpoint to exchange these credentials for a bearer token.
When accessing the REST API, the application uses the bearer token to authenticate.
The steps are detailed in the documentation.
You can do the first 2 separately and when you get your bearer token, you need to add a specific HTTP Header (Authorization) in each request with your bearer token (that's the 3rd step). With jQuery it could be something like that:
$.ajax({
headers: { Authorization: 'Bearer '+$my_bearer_token },
url: 'https://api.twitter.com/1.1/search/tweets.json?q='+$search
}).done(function (data) {
// Play with the data
});
file_get_contents not working with following url (failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request)
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=235326466577139&redirect_uri=http%3A%2F%2Fapps.facebook.com%2Flikeablephotos%2F&client_secret=CLIENT_SECRET&code=AQDFZbjpAUda8c_gz4wDDuBOVrsn0dApz3s8UA--7hFQIi1wb70-tDE56xXcCtDq-hV5UWzR5YEw_ozuGT24FLfvh9KnqHZ3xdn46P_KxYCf3DHJQA3AAu2ICHBqTk1-6fHTsl6FbagKz83H6dn15kkbKksajA4KcVIoPse5JbuBLlh6V5L1ANe8fzR94iH_SMU";
$response = file_get_contents($token_url);
but if you copy and paste the above URL into the browser address bar it works just fine! and returns:
access_token=AAADWBzZAyUvMBAL2Th6CRtxh2Up5soTCK8N4HJcy0ZBhQgJPxtZArKbuITISMoGLDxNiyeNW4GUZCBvJPeBTH6mx4v83ueUIAAYQJA1WrAZDZD&expires=5112501
but his similar URL (for a different user) also works:
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=235326466577139&redirect_uri=http%3A%2F%2Fapps.facebook.com%2Flikeablephotos%2F&client_secret=CLIENT_SECRET&code=AQC2kTEV96-1Cki2oYUhyzjH6yFe6AJRd1Q3G8fbUXW-IsLJUlactzSwCvGVBK6jh1tL-t7v6dOWJZzbkSYhk0n2z6BHQcpljWAdoXFGB5zLC4FgW8fmxT6hwdRIQOr2dZ95CD_q5yJuOUz_2DItUa3_FF9m2_TmFYGEbxPoiaF47YSTUuZp6g-8ffziJcKDAdo";
when using file_get_contents
Please help, thanks
As an alternative to file_get_contents have you considered using cURL. I use curl for alot of requests with great results and on fail it will not expose your client secret.
refer to http://php.net/manual/en/book.curl.php
this code snippet is a standard for all my apps to get application access token. Can be used for all api calls.
$app_access_token = GetCH();
function GetCH(){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=client_credentials");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
if(substr($url,0,8)=='https://'){
// The following ensures SSL always works. A little detail:
// SSL does two things at once:
// 1. it encrypts communication
// 2. it ensures the target party is who it claims to be.
// In short, if the following code is allowed, CURL won't check if the
// certificate is known and valid, however, it still encrypts communication.
curl_setopt($ch,CURLOPT_HTTPAUTH,CURLAUTH_ANY);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
}
$sendCH = curl_exec($ch);
curl_close($ch);
return $sendCH;
};
Finally found the answer, had the same issue..the problem is most likely because facebook's code that they give you has spaces in between the params. If you just copied and pasted from Facebook, you will get a HTTP/1.1 400 Bad Request error. Put all the params on one line and remove all spaces and this should fix it. Worked for me. I know this is an older post but if you are having this problem let me know if it works for you!
For debugging:
Take the actual string in $token_url and paste into a browser address field and see what happens.
You will get some back some json error code.
For me, it was the my token was expired. Starting fresh request worked fine.
same problem happened to me the problem was access token supplied with the URL was expired since access token have 1 hour validity ,so i created a new access token and it works again ,hope this info helps .