Search code examples
androidapiurlhttpspushbullet

Pushbullet API via http in Android


How can I receive Pushbullet notes/images/profile details via API-Key on Android? My main problem is the SSL security in that point. (BTW: I'm pretty much a beginner in Android and only know the basics.)

The auth looks like this:

https://apikey@api.pushbullet.com/v2/users/me

I'm successfully requesting the content of a webpage (e.g. wikipedia.org) via

try {
    URL url = new URL("https://www.wikipedia.org");
    URLConnection urlConnection = url.openConnection();
    InputStream in = urlConnection.getInputStream();
    StringWriter writer = new StringWriter();
    IOUtils.copy(in, writer);
    theString = writer.toString();
    textView.setText(theString);
} catch (Exception e) {
    textView.setText("Error: "+e "String content: " +theString);
}

but when I'm requesting, for example, my profile details I'm always getting a

javaio FileNotFoundException


Solution

  • If you run your requests through https://www.runscope.com you can often see what the request is that your client is actually making (they have a free plan for trying it out).

    If I had to guess I would say it's likely the authorization is not working correctly. Are you able to get that page using curl? It should look something like:

    curl -u <apikey>: https://api.pushbullet.com/v2/users/me
    

    Assuming that works, try something like

    urlConnection.setRequestProperty("Authorization", "Bearer <apikey>");
    

    or however it is you set headers on your HTTP requests. This is more explicit than relying on the https://password@domain url thing.