Laravel push notification. How to get devices token? -fcm - laravel

I have a webview application. I wrote the project in Laravel. I want to use push notifications. But how can I get device tokens? where can I find it?
$push->setMessage([
'notification' => [
'title'=>'This is the title',
'body'=>'This is the message',
'sound' => 'default'
],
'data' => [
'extraPayLoad1' => 'value1',
'extraPayLoad2' => 'value2'
]
]);
$push->setApiKey('Server-API-Key');
$push->setDevicesToken(['deviceToken1'
,'deviceToken2',
'deviceToken3'
]);
what is deviceToken1 2 3?
I created a project in Firebase. I can get the API. But how can I find and save devices' tokens? I cannot send a notification to the screen.

So basically, you should use Firebase SDK in your front-end to get the device ID/token, then send it to your server/Laravel (save it in your DB for later use).
There are different ways to get the device ID based on what front-end you're using, you can refer to these documentations:
Android
IOS
Web
Others (C++, Unity, etc.)

Related

Laravel validate iOS recorded voice

I have put some mime type validation on my Laravel controller to validate received file from mobile applications:
'file' => 'required_without:body|file|mimes:png,jpg,jpeg,mp3,mp4,pdf,doc,docx,m4a'
This validation rule is OK for most of files, but when iOS app sends recorded voice, this validation rule doesn't work.
Based on what iOS developer says, the file's mime type is audio/m4a but laravel (or maybe PHP) can't detect that.
I checked that $request->file('file')->getClientOriginalExtension() returns audio/m4a but $request->file('file')->guessExtension() function returns null!
Any help is appreciated.
This is what I did and I believe it is a good practice:
After some tracing that what laravel does to guess mimetypes, I noticed that it is registering some ExtensionGuesser classes like vendor/symfony/http-foundation/File/MimeType/MimeTypeExtensionGuesser.php and there was no audio/m4a mimetype.
I provided AnotherMimeTypeExtensionGuesser containing:
protected $defaultExtensions = array(
'audio/m4a' => 'm4a',
'audio/x-m4a' => 'm4a',
'audio/mp4' => 'm4a',
);
And then I registered it in my AppServiceProvider like this:
ExtensionGuesser::getInstance()->register(new AnotherMimeTypeExtensionGuesser);
use this rule in your validation
'file' => 'required_without:body|file|mimetypes:audio/mp4|mimes:m4a'

Send push notification by using Parse from laravel web server to android device

I cant find how to send push notification by using Parse.com from my web server to android device using laravel. can anybody help me ?
Take a look at this documentation:
https://parse.com/docs/php/guide#push-notifications
and to this GitHub project:
https://github.com/ParsePlatform/parse-php-sdk
This PHP Lib can be included to your laravel project
Push:
ParseClient::initialize( $app_id, $rest_key, $master_key );
$data = array("alert" => "Hi!");
// Push to Channels
ParsePush::send(array(
"channels" => ["PHPFans"],
"data" => $data));
// Push to Query
$query = ParseInstallation::query();
$query->equalTo("design", "rad");
ParsePush::send(array(
"where" => $query,
"data" => $data));
You have to delegate the Parse itself to send your push notification instead of using your web server (more secure). So, you can manage this delegation via writing a cloud function in Parse backend, and call this cloud function from your web server. From links in comment section of post, you can call the cloud function via the Php SDK of Parse;
$results = ParseCloud::run("aCloudFunction", array("from" => "php"));
In cloud function, you have to query the installation table and find the user and send your push.Hope this helps.
Regards.

API and "normal" URLs in one Yii2 application

I would like to have (use) in my Yii2 application:
a standard, SEO-like URLs, with .html at the end (thus 'suffix' => '.html') and
API request (basing on very simple code) without this suffix.
So, to make my application being able to serve both http://127.0.0.1/app/site/index.html-like URLs and http://127.0.0.1/uslabs/web/user/2-like API calls.
It this possible? If so, how should I configure urlManager component for this?
I went through "Quick Start" chapter in "RESTful Web Service" section, but it bring no help. They don't use suffixes in examples given there. I'm stuck with the choice of either one or other scheme.
Yii has a REST url router that you can use to associate with certain controllers, like this;
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'suffix' => 'html',
'rules' => [
['class' => 'yii\rest\UrlRule',
'controller' => 'api',
'suffix' => NULL],
],
]
See the documentation for more details
According to this Yii Forum post, what I'm trying to do is possible, but tricky and not encouraged.
API calls should be handled by a separate application. At the end of "Quick Start" part for API-like apps in Yii2 guide there's a suggestion:
While not required, it is recommended that you develop your RESTful APIs as a separate application, different from your Web front end and back end for easier maintenance.

o-auth login with wykop.pl

Now I wish to build a login function with Wykop.pl API.
Can anybody help me to setup the thing?
As of now, I don't even have clue how to fill the
'scope' => array()
not to mention which privileges I should enable when connecting my app to wykop.pl
'Wykop' => array(
'client_id' => '423423',
'client_secret' => '0XMRI423423BfDFG',
'redirect_url' => 'http://www.appname.pl/dashboard',
'scope' => array('login', 'klucz_polaczenia','profile'),
),
This is a SDK for the site https://github.com/p1c2u/wykop-sdk
Unfortunately, as for now I am unable to translate the code into sth useful to me.
For the purpose of o-auth login, should scope include 'login' and 'klucz_polaczenia' ?
After the function is done, it would be a good idea to add the example to
this project repository of examples:
https://github.com/Lusitanian/PHPoAuthLib/tree/master/examples
Edit:
Wykop is not using o-auth... so the package I was trying to use is of no value.
Any help appreciated.
Edit 2:
The clostest I got to my goal is using this repo:
https://github.com/matiit/wkop
I did this recently. I'm using following workflow:
Display the login form to the user, with redirect set to callback.
Check the signature of callback, if correct then proceed.
Check, if I can login on Wykop.pl with received token, if so, then proceed.
Check, if user exists in my database, if so, I login him, if not, I create and login him.
Whole process of connecting with Wykop.pl API is available here: http://www.wykop.pl/dla-programistow/dokumentacja/#info6_7_5

Why can Gibbon Gem access API but can't listSubscribe()?

I'm trying to get mailchimp integrated with my ruby-on-rails app using the Gibbon gem.
I've successfully accessed the API. I tested it by getting a list of all my mailchimp lists. However, I'm running into problems with the listsubscribe method. I'm not getting any errors, it just isn't working at all.
I have the following code in the controller for the page where users sign up, after the user is made and their information can be accessed.
gb=Gibbon::API.new
gb.listSubscribe({:id => "the-id-for-list", :email_address => user.email, :update_existing => false, :double_optin => false, :send_welcome => true, :merge_vars => {'FNAME' => user.first_name, 'LNAME' => user.last_name, 'MERGE3' => user.subscription, 'MERGE4' => DateTime.now}})
It does nothing. I've tried playing around with the parameter phrasing (à la this post:How do you use the Gibbon Gem to automatically add subscribers to specific interest groups in MailChimp?) I've tried structuring it more like in this tutorial: http://www.leorodriguez.me/2011/08/subscribe-member-into-mailchimp-using.html
I have no idea what's going wrong. As I said before, other API calls are going through to MailChimp. Do you have any suggestions? Thank you in advance.
It turns out I had the code in the wrong place. I was not putting it where users were actually being created, but in the code to generate the view to ask users to sign up. Once I moved it to where the user was actually created, it worked fine.

Resources