Interested in sending Pushbullet Pushes with B4A?

DonManfred

Expert
Licensed User
Longtime User
Just want to know whether you are interested or not...

Getting/reading the following Data i already have:
- ME (info about my account)
- Contacts (lists my contacts)
- Subscriptions (lists my subscriptions)
- Devices (lists my devices)

Pushes already send is not ready actually

I´m working on "Sending a Push to one or more devices or to a contact" actually...

PS: I´m just using B4A, httputils and JSON
 

DonManfred

Expert
Licensed User
Longtime User
simple httputils-calls....

App a sends a httprequest to pushbullet-server. Pushbullet-server sends this then to app b

As the sending of a push is not ready yet i show you an example of getting "me"
It gets informations about your account... id, created and so on...

B4X:
    Dim Const PB As String = "https://api.pushbullet.com/v2/"
  
    ' Get information about the current user.
    Dim Const PBme As String = PB&"users/me"
[..]
    Dim job As HttpJob
    job.Initialize("ME",Me)
    job.Download(PBme)
    job.GetRequest.SetHeader("Authorization", "Bearer "&secret)


Sub JobDone (job As HttpJob)
    LogColor("JobDone ("&job.JobName&")",Colors.Blue)
    If job.Success = True Then
        Select job.JobName
      Case "ME"
          lv.Clear
            Log(job.GetString)
            Dim parser As JSONParser
            parser.Initialize(job.GetString)
            Dim root As Map = parser.NextObject
            Dim iden As String = root.Get("iden")
            lv.AddTwoLines2(iden,"iden",root)

            Dim email As String = root.Get("email")
            lv.AddTwoLines2(email,"eMail",root)
          
            Dim name As String = root.Get("name")
            lv.AddTwoLines2(name,"Name",root)

            Dim created As Double = root.Get("created")
            lv.AddTwoLines2(created,"Created",root)

            Dim google_userinfo As Map = root.Get("google_userinfo")
            Dim name As String = google_userinfo.Get("name")
            Dim email_normalized As String = root.Get("email_normalized")
          
            Dim preferences As Map = root.Get("preferences")

            Dim onboarding As Map = preferences.Get("onboarding")
            Dim extension As String = onboarding.Get("extension")
            Dim app As String = onboarding.Get("app")
            lv.AddTwoLines2(app,"App",root)
            Dim friends As String = onboarding.Get("friends")
            lv.AddTwoLines2(friends,"Friends",root)
            Dim mac As String = onboarding.Get("mac")
            lv.AddTwoLines2(mac,"Mac",root)
            Dim modified As Double = root.Get("modified")
            lv.AddTwoLines2(modified,"Modified",root)
            Dim image_url As String = root.Get("image_url")
[...]
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Actually no... I´m working on sending the pushes and on creating the sample app

Hopefully i get all working till weekend

If you want to help

https://docs.pushbullet.com/v2/pushes/

Target Parameters

Each push has a target, if you don't specify a target, we will broadcast it to all of the user's devices. Only one target may be specified.

device_iden - Send the push to a specific device. Appears as target_device_iden on the push. You can find this using the /v2/devices call.
email - Send the push to this email address. If that email address is associated with a Pushbullet user, we will send it directly to that user, otherwise we will fallback to sending an email to the email address (this will also happen if a user exists but has no devices registered).
channel_tag - Send the push to all subscribers to your channel that has this tag.
client_iden - Send the push to all users who have granted access to your OAuth client that has this iden.

But i cant find any sample which set the target to a special device or a email so i dont know how to USE the target....

Drop me an info if anyone knows
 
Last edited:

udg

Expert
Licensed User
Longtime User
Hi Manfred,

thank you very much to have driven my attention to this service. It sounds very interesting!
I've just started reading the docs you linked, so what follows could be entirely wrong, but have a look at it anyway.

It is my understandig that to send a note to a specific device you should call:
B4X:
Dim PBService AsString = "https://api.pushbullet.com/v2/pushes/"
Dim TargetDevice as string = "udm0Tdjz5A7bL4NM" ' sets the target devices's device_iden here; a list is provided by v2/devices API

Dim job AsHttpJob
job.Initialize("ME",Me)
job.Download(PBService&TargetDevice)
'set header 'Content-Type: application/json
'set data-binary '{"type": "note", "title": "Note Title", "body": "Note Body"}'
 job.GetRequest.SetHeader(...)

Are you coding a class/library to make use of PB? Do you plan to use it for any specific project (like an "help me" message send to all the registered/channeled devices)?

udg
 

udg

Expert
Licensed User
Longtime User
My probably wrong idea is that the target_id should immediately follow the word "pushes" in the URL submitted to job.download.
I've just signed for the service so I may experiment a bit myself too, now.
 

DonManfred

Expert
Licensed User
Longtime User
Are you coding a class/library to make use of PB? Do you plan to use it for any specific project (like an "help me" message send to all the registered/channeled devices)?
I dont know whether i should make a class or lib...actually it is only just simple b4a code using httputils...

I dont have a specific project in mind. I found Pushbullet a week ago and find it VERY useful (for MY use) so i decided to write code to manage the pushes or devices... As i´m not limited to a specific project I´m open for all possibilities.
 

DonManfred

Expert
Licensed User
Longtime User
Its a param so put
thanx for you answer... I´ll try to use this in the post-json-payload (not using get-parameter as you suggested)

I thought kind of the same but i did not had the time to test this actually.

without setting a target (and this works here) the request looks like this

B4X:
Sub Button1_Click
    Dim json As JSONGenerator
    '--data-binary '{"type": "note", "title": "Note Title", "body": "Note Body"}'
    json.Initialize(CreateMap("type": "note", "title": subject.Text, "body": body.Text))
  
    Dim job As HttpJob
    job.Initialize("PUSH",Me)
    job.Poststring(Main.PBpushes,json.ToString)
    job.GetRequest.SetHeader("Authorization", "Bearer "&Main.secret)
    job.GetRequest.SetHeader("Content-Type", "application/json")
      
End Sub
The push will be send to all my devices
 

udg

Expert
Licensed User
Longtime User
Hi all,

please find attached a working example of sending a note to a single device ..well, at least I hope so, since I have only one device :D

udg

ps: insert your secret key in the process global var named secretkey

Edit: post #16 and #17 almost at the same microsecond.. eheh
 

Attachments

  • PBTest1.zip
    7.4 KB · Views: 250

DonManfred

Expert
Licensed User
Longtime User
well, at least I hope so, since I have only one device
When it works for you then the use of the device_iden is correct. Great! This will help me :cool:

But your code will work only for the LAST device listed in the result of devices... there is a foreach loop and you are using the last iden set in this loop...

Thank you for your investigation!
 

udg

Expert
Licensed User
Longtime User
Hi Manfred,

But your code will work only for the LAST device listed in the result of devices

that was intentional since it was my first test and I didn't register any other device.
My goal was just to have something working as a starting point to further investigation.
I am attracted by Channels (setting one and then having a few friends to send notes to).

BTW, do you know if all this PB world is free?
 

DonManfred

Expert
Licensed User
Longtime User
BTW, do you know if all this PB world is free?
I did not see any pro account. I also did not get any mail offering me a pro account or so.

Honestly: I dont know

When it works for you then the use of the device_iden is correct.
If you dont set a target then you will get pushed to all your devices.
So i dont know whether the parameter is accepted or not as target.
I´ll do my own investigations on it today for sure... I´ll inform you if i find out something :)
 
Top