Pushwoosh: Set Badge with PHP API - php

I'm using a paid Pushwoosh Account in order to send programmatically push-notifications to my users.
I've implemented the Pushwoosh PHP SDK and everything works great, but I'm not able to set a Notification-Badge on iOS devices as seen on the following image:
My code so far is:
$devicesArr[] = ...
$pushwoosh = Pushwoosh::create()
->setApplication('79XXX-9CXXX')
->setAuth('Wkf...2C8');
//Create the Message
$request = CreateMessageRequest::create()
->addNotification(Notification::create()
->setContent('A new workout is available!')
->setDevices($devicesArr));
//Call the REST Web Service
$response = $pushwoosh->createMessage($request);
I tried to use the ->setBadge(5) method according to this page but this also does not work:
$request = SetBadgeRequest::create()
->setBadge(1)
->setHwid('18D...1AF');
Do you know how I can achieve my goal?

I can't reproduce this on Cordova Sample (https://github.com/Pushwoosh/pushwoosh-phonegap-cordova-sample/tree/master/Phonegap-iOS-Android-WP), can you share a simple sample?
Are you sure the app is closed when you receive push with badge?

Per the docs, this is not the method you use to set the badge number on the device.
Important
This method IS NOT used to update the badge value on the device.
Instead please use /createMessage request with the "ios_badges" parameter.
http://docs.pushwoosh.com/docs/setbadge

Related

Cannot Verify Shopify Webhook

I have setup a webhook in shopify via settings > notifications > webhooks and entered a heroku app URL. My heroku app is in php and I run the verification function found here: https://shopify.dev/tutorials/manage-webhooks and when I open my app I get a blank response. I am not sure if this is something I am doing wrong on my heroku app, or if I am missing something. The goal here is to grab the json data after the event I have selected is ran, then to send that data to via third party api. But to start I just want to be able to verify that my heroku app is receiving the payload. Is there more I need to add to my php file in order to verify? (php noob here). Below is the code I am running in my php file, and yes I am using my shared secret found in the webhooks section.
<?php
define('SHOPIFY_APP_SECRET', 'my_shared_secret');
function verify_webhook($data, $hmac_header)
{
$calculated_hmac = base64_encode(hash_hmac('sha256', $data, SHOPIFY_APP_SECRET, true));
return hash_equals($hmac_header, $calculated_hmac);
}
$hmac_header = $_SERVER['HTTP_X_SHOPIFY_HMAC_SHA256'];
$data = file_get_contents('php://input');
$verified = verify_webhook($data, $hmac_header);
error_log('Webhook verified: '.var_export($verified, true)); //check error.log to see the result
?>
If I am not mistaken you cannot test webhooks that way as the admin does not use your API key as it has no idea who you are when in the admin. So if you have a heroku App and it has an API key, use that API key to first off establish the webhook, verify you created it with the API, and then sit around and test your actual endpoint with Shopify Admin itself. That is how it works AFAIK.
The other verification in the admin is mickey mouse and meant to just throw data at any old endpoint with no validation.

Callback error on YouTube socialite provider for Laravel

I am trying to set up Oauth with the YouTube Data API. I had a Laravel app which has Socialite set up. Out of the box YouTube isn't set up with this but I saw that there is a provider for YouTube here:
https://socialiteproviders.netlify.app/providers/you-tube.html
I have done all of the steps outlined on the page along with all routes that I need. I have also done the Oauth set up on Google Developer Console and got the client ID/secret key and set the callback.
When I use the login URL it works where I'm redirected for login with Google. The problem comes when the callback URL is reached. I get the error:
ErrorException
Undefined index: items
This occurs on the provider callback function which has the code:
$user = Socialite::driver('youtube')->user();
I have tried using stateless:
$user = Socialite::driver('youtube')->stateless()->user();
But get the same error. All caches have been cleared. I am pretty sure that the setup was done correctly as I'm also using the Twitch provider from https://socialiteproviders.netlify.app/providers/twitch.html which the setup was similar and it works correctly.
Please can anyone advise? Thanks.
Try selecting the fields you want to access first:
$user = Socialite::driver('youtube')->fields([
'items'
])->user();
I'm facing the same issue. Is it possible that the API has changed? If I take a look at the raw response there
I also stumbled onto this issue:
When I tested it, I did not got the error, but my colleague did so I figured it had something to do with the account that tried to connect.
I changed my approach from:
$user = Socialite::driver('youtube')->stateless()->user();
And just received tokens by doing this:
$socialite = Socialite::driver('youtube');
$code = $request->input('code');
$response = $socialite->getAccessTokenResponse($code);
$response will contain an array of tokens. I used these tokens to connect it to an existing user in my database.
I don't know if this is the solution for your workflow, but it is a way to get around the mysterious error.
The issue is due to YouTube no longer automatically creating a channel for your google/gmail account like it did in the past. This results in responses completely missing an items array.
if you dd($response->getBody()->getContents()) the response for an account that throws an error you'll see this.
I've made a pull request for this here. https://github.com/SocialiteProviders/YouTube/pull/8

Create a webhook programmatically in wordpress/woocommerce

i'm making a Plugin to make a integration of one ERP to Woocommerce and i'm thinking about using the web hooks for that integration, the problem create the web hooks when the plugin is activated for the first time, and not oblige people to create the woocommerce webhooks manually and configure them. i googled and tried several things but looks like no one works, also tried make a sql query, but don't worked.
i tried this:
function createWebhook($userID,$topic,$secret,$deliveryURL,$status)
{
$webhook = new WC_Webhook();
$webhook->set_user_id($userID); // User ID used while generating the webhook payload.
$webhook->set_topic( $topic ); // Event used to trigger a webhook.
$webhook->set_secret( $secret ); // Secret to validate webhook when received.
$webhook->set_delivery_url( $deliveryURL ); // URL where webhook should be sent.
$webhook->set_status( $status ); // Webhook status.
$save = $webhook->save();
return $save;
}
from this thread
without sucess, getting a lot of errors.
Anyway, thanks for the help. and i hope you'r ale in safety and with good health!
You are missing the webhook name
Add $webhook->set_name('Webhook Name');

Is it possible to add a ticket response as a specific user via the SoftLayer API using the PHP SOAP client?

I'm attempting to use the SoftLayer API (via the PHP client) to add an update to an existing ticket, as a specific user under our main account (a sibling to our API user).
What I'm trying to achieve is that as the API user, I call SoftLayer_Ticket::addUpdate, passing a SoftLayer_Ticket_Update object that looks similar to:
{
editorID: user1_id_here,
editorType: "USER",
entry: 'My update here'
}
I have user1's ID, however when I pass it in the SoftLayer_Ticket_Update object, the update is still attached as the API user:
{
createDate:"2016-05-17T08:24:50-07:00"
editorId:api_users_id
editorType:"USER"
entry:"Another update for our glorious leader..."
id:#########
ticketId:########
}
Snippet of the ticket update code:
$slClient = \SoftLayer_client::getClient("Ticket", $ticketID);
$ticketUpdateObj = new \stdClass();
$ticketUpdateObj->entry = $update;
$ticketUpdateObj->editorId = ######;
$ticketUpdateObj->editor = ######;
$ticketUpdateObj->editorType = "USER";
$result = $slClient->addUpdate($ticketUpdateObj);
...
(do other stuff here)
Is there any way to do this with the SoftLayer API? Or is the issue stemming from permissions given to the API user, or that I'm attempting to add the update as a sibling to the API user? Any help would be appreciated!
Our platform is older, so we are using an older version of the SoftLayer PHP SOAP client (guessing circa 2010/early 2011).
Thank you in advance!
Sorry, that is not possbile you cannot set the editorId, this value is set by the system with the userID of the user who updated the ticket.
Regards

How to insert and retrieve postBody in Mirror API account insert method using PHP

I need to insert user's email in postBody of mirror API insert method. I am using this code:
$authtoken=null;
$postBody = new Google_Service_Mirror_Account();
$postBody->setAuthTokens($authtoken);
$userdata=array("email"=>$email);
$postBody->setUserData($userdata);
$account = $service->accounts->insert($userToken, package-name-here, $accountName, $postBody);
The above method returns null in response! I am not sure what to add as authtoken.
After this, I need to retrieve user's email account through Android's account manager:
AccountManager manager = AccountManager.get(c);
Account[] list = manager.getAccountsByType(package-name-here);
for (Account acct : list) {
accountEmailId= manager.getUserData(acct, "email");
break;
}
This doesn't seem to work. I do not get accounts of this type in Glass device. Any help will be great.
EDIT:
Added the authTokenArray and userDataArray to postBody as suggested below:
$userDataArray= array();
$userData1= new Google_Service_Mirror_UserData();
$userData1->setKey('email');
$userData1->setValue($email);
$userDataArray[]=$userData1;
$authTokenArray= array();
$authToken1= new Google_Service_Mirror_AuthToken();
$authToken1->setAuthToken('randomtoken');
$authToken1->setType('randomType');
$authTokenArray[]=$authToken1;
$postBody = new Google_Service_Mirror_Account();
$postBody->setUserData($userDataArray);
$postBody->setAuthTokens($authTokenArray);
Account insert method still returns null. Unable to solve the issue till now.
[SOLVED]
Mirror API still returns NULL response, but account is actually being inserted in Mirror API. Updated code can be viewed here: http://goo.gl/DVggO6
setAuthTokens takes an array of Google_Service_Mirror_AuthToken objects (see the source here), each of which has an authToken (an arbitrary string of your choosing) and a type (another arbitrary string). These values are copied directly into the account in the Android AccountManager so that you can look them on the device.
Your problem might be coming from the fact that you're passing in null for that right now. I would try fixing that and then see if you're able to see the account on the device.

Categories