Interested in sending Pushbullet Pushes with B4A?

DonManfred

Expert
Licensed User
Longtime User
a working example
It does work cause you did not set a correct target. If no target is set you get the push to all your devices. THAT´s happening here.


THIS works (tested pushes to one specific device and also send a push to a contact)...

B4X:
Sub Button1_Click
    Dim json As JSONGenerator
    '--data-binary '{"type": "note", "title": "Note Title", "body": "Note Body"}'
    If Main.aktdest.ContainsKey("email") Then
        ' Map contains key email
        ' -> It is a CONTACT
        json.Initialize(CreateMap("email": Main.aktdest.Get("email") ,"type": "note", "title": subject.Text, "body": body.Text))
        Label1.Text = "Contact: "&Main.aktdest.Get("name")
    End If
    If Main.aktdest.ContainsKey("manufacturer") Then
        ' Map contains key manufacturer
        ' -> It is a DEVICE
        json.Initialize(CreateMap("device_iden": Main.aktdest.Get("iden") ,"type": "note", "title": subject.Text, "body": body.Text))
        Label1.Text = "Device: "&Main.aktdest.Get("nickname")
    End If
   
    Dim job As HttpJob
    job.Initialize("ME",Me)
    job.Poststring(Main.PBpushes,json.ToString)
    job.GetRequest.SetHeader("Authorization", "Bearer "&Main.secret)
    job.GetRequest.SetHeader("Content-Type", "application/json")
       
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Informationupdate
Umberto and i got it working yesterday in the evening.

We now can:
- Get a Map with my account-details
- Get a list of all my devices
- Get a list of all my contacts
- Get a list of all my subscriptions (channels i subscribed).
(that all was done by me before already)

- Send a push to all devices of the secret-holder (all MY devices)
- Send a Push to a specific device using it´s uniqu iden
- Send a Push to a specific contact fom my contacts using it´s email
- Send a Push to a Channel i am owner of (everybody can subscribe to this channel to get new pushes easily).

Actually we only used the Push type "Note" (Subject, body) but as the other types are similar this should work too! Though it is not tested actually (but weekend is just in front of the door :D)
 

udg

Expert
Licensed User
Longtime User
Actually he is Manfred who did all the work 'till now.
I started with his code from post#4 and did experiment a bit myself. Then we collaborated on how to send notes to a specific recipient or to a group by way of channels.
I am sure we will end up with a clean and easy to use class/library where to summarize all of our findings.
Anyone is invited to join us..
 

DonManfred

Expert
Licensed User
Longtime User
Update:

We are now able to use an OAuth-authentification-flow to get an access-token on YOUR behalf...
The app shows up a webview where you can login to your pushbullet-account and you then can approve the auth-client.
The app will return an request-token and then the app uses this token to communicate with pushbullet "in your name"

The only thing we could not get to work actually is sending a push with a file attached.
 

udg

Expert
Licensed User
Longtime User
I am working on it right now.
I found an interesting doc about multipart/form data here.
The subject is new to me but I'll surely learn something

Edit: and this one should be the right one to finally have a successful file upload
 
Last edited:

udg

Expert
Licensed User
Longtime User
After several hours I haven't a working upload yet :(

Depending on which of my test functions I use, my attempts result in error:
Invalid Argument: POST requires exactly one file upload per request
OR
Incomplete Body: The request body terminated unexpectedly

I know I am close, but ... ok, time for dinner and some rest.
 
Top