In questa pagina fornisco i codici script per inviare un push di Pushbullet. Si prega di prendere nota dei seguenti requisiti:
Per maggiori informazioni sulle API di Pushbullet, fare riferimento a questa pagina.
#!/bin/bash token_id="" body="My body" title="My Title" type="note" json="{\"type\":\"$type\",\"body\":\"$body\",\"title\":\"$title\"}" accesstoken=$(printf "Access-Token: %s" $token_id) curl_return=$(/opt/bin/curl --header "$accesstoken" \ --header 'Content-Type: application/json' \ --data-binary "$json" \ --request POST \ https://api.pushbullet.com/v2/pushes) echo $curl_return
#!/bin/bash token_id="" body="My body" title="My Title" link="http://www.google.com" type="link" json="{\"type\":\"$type\",\"body\":\"$body\",\"title\":\"$title\",\"url\":\"$link\"}" accesstoken=$(printf "Access-Token: %s" $token_id) curl_return=$(/opt/bin/curl --header "$accesstoken" \ --header 'Content-Type: application/json' \ --data-binary "$json" \ --request POST \ https://api.pushbullet.com/v2/pushes) echo $curl_return
Per inviare un file, ci sono due modi. Nel primo modo,
bisogna avere un file già disponibile. Nel secondo modo, si recupera un file da Internet.
Il seguente script, recupera un file già presente nella stessa cartella dello script.
#!/bin/bash token_id="" body="My body" title="My Title" file_name="picture.jpg" file_type=$(file -i -b $file_name) json="{\"file_name\":\"$file_name\",\"file_type\":\"$file_type\"}" accesstoken=$(printf "Access-Token: %s" $token_id) curl_return=$(/opt/bin/curl --header "$accesstoken" \ --header 'Content-Type: application/json' \ --data-binary "$json" \ --request POST \ https://api.pushbullet.com/v2/upload-request) file_name=$(echo $curl_return | /opt/bin/grep -oP '"(file_name)":"\K.*?(?=")') file_url=$(echo $curl_return | /opt/bin/grep -oP '"(file_url)":"\K.*?(?=")') file_type=$(echo $curl_return | /opt/bin/grep -oP '"(file_type)":"\K.*?(?=")') upload_url=$(echo $curl_return | /opt/bin/grep -oP '"(upload_url)":"\K.*?(?=")') /opt/bin/curl -i -X POST $upload_url -F file=@$file_name type="file" json1="{\"type\":\"$type\",\"title\":\"$title\",\"body\":\"$body\",\"file_name\":\"$file_name\",\"file_type\":\"$file_type\",\"file_url\":\"$file_url\"}" ret_curl=$(/opt/bin/curl --header "$accesstoken" \ --header 'Content-Type: application/json' \ --data-binary "$json1" \ --request POST \ https://api.pushbullet.com/v2/pushes) echo $ret_curl
Il seguente script, recupera un file da Internet.
#!/bin/bash token_id="" body="My body" title="My Title" file_name="pexels.jpg" file_url="https://images.pexels.com/photos/1681148/pexels-photo-1681148.jpeg" file_type="image/jpeg" accesstoken=$(printf "Access-Token: %s" $token_id) type="file" json="{\"type\":\"$type\",\"title\":\"$title\",\"body\":\"$body\",\"file_name\":\"$file_name\",\"file_type\":\"$file_type\",\"file_url\":\"$file_url\"}" curl_return=$(/opt/bin/curl --header "$accesstoken" \ --header 'Content-Type: application/json' \ --data-binary "$json" \ --request POST \ https://api.pushbullet.com/v2/pushes) echo $curl_return