Categories
Laravel

Laravel API POST methods request return a 419 status code when we browser by dev server.

If the browser cannot access the Laravel API post routes at localhost, it will always return an HTTP 419 error status, with the CSRF token mismatch exception. We need to changes in the Laravel app/Http/Middleware/VerifyCsrfToken.php file.

This code is located in the handle method of the parent class of VerifyCsrfToken.php, which is found at vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php.

Solution: Simply add the isReading() method to the file verifyCsrfToken.php to enable the POST method.

Categories
Google API Laravel

How can we setup the Google APIs Client Library in Laravel 10?

Setting up the Google APIs Client Library and access using Service Account in Laravel involves several steps. This library allows you to integrate various Google APIs, such as Google Drive, Google Sheets, etc., into your Laravel application. Here’s a step-by-step guide to help you set it up:

Note: Before you begin, make sure you have Composer installed and your Laravel project is up and running.

Create a New Laravel Project (Optional):

Install Google API Client Library:

Use Composer to install the Google APIs Client Library

Create Google API Project and Get Credentials:

Enable the Required API:

  • In the Cloud Console, navigate to the “APIs & Services” > “Library” section.
  • Search for the API you want to use (e.g., Google Sheets, Google Drive) and enable it for your project.

Create a Service Account:

  • In the Cloud Console, navigate to the “APIs & Services” > “Credentials” section.
  • Click on “Create credentials” and select “Service account key.”
  • Follow the prompts to create a new service account. Give it a name and assign it the necessary permissions based on the API you’re using (e.g., Editor or Viewer access).
  • Download the JSON key file for the service account. This file will be used in your Laravel project.

More details google developers console to generate service-account credentials.

Upload your service account json file to “storeage/app/public/service-account.json” directory.

Configure Laravel Environment:

Open your Laravel project’s .env file and add the following lines, replacing the placeholders with your actual credentials:

Assign google Service Account config:

Create Routes and Controllers:
Test Your Application:

Access the application in your browser and navigate to the http://sitedomain.com/drive/all/files route to get list of all files and folder.

Categories
Others

How to create a subdomain and link with in Cloudflare?

In this article I will discuses how create and pointing a new subdomain if your existing domain is configure and point to Cloudflare.

Subdomain link with Cloudflare

First you want to create subdomain in Namecheap, Siteground, Godaddy or your existing hosting server. It’s requires you to add the CNAME record on Cloudflare pointing to your registered domain.

Login into your Cloudflare account, click on the active domain in which you need to create this subdomain. Click on DNS from left menu and click on Add record button.

Enter the subdomain as the name for instance add “staging” (or what you want) name here. In the target add your registered domain name example yourdomain.com

Finally click on Save button.

Cloudflare is quick you should be able to reach the sub domain as soon as (within 10 or 20 minutes) you added.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Hope it will help you.

Categories
Laravel

Laravel – Failed to authenticate on SMTP server with username using 3 possible authenticators

If you still get following error (Failed to authenticate on SMTP server with username) when sending email please follow below steps.

Swift_TransportException

Failed to authenticate on SMTP server with username “yourid@gmail.com” using 3 possible authenticators. Authenticator LOGIN returned Expected response code 235 but got code “535”, with message “535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials c17-20020a170902d49100b001624cd63bbbsm4334145plg.133 – gsmtp “. Authenticator PLAIN returned Expected response code 235 but got code “535”, with message “535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials c17-20020a170902d49100b001624cd63bbbsm4334145plg.133 – gsmtp “. Authenticator XOAUTH2 returned Expected response code 250 but got code “535”, with message “535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials c17-20020a170902d49100b001624cd63bbbsm4334145plg.133 – gsmtp “.

Step 1:

Please login into your gmail account and click on “Manage your Google Account” button form right to your profile picture.

Manage your Google Account

Step 2:

Go to to Security tab form left menu and please turn on 2-Step Verification by using your Recovery Phone.

2-Step Verification

Step 3:

Click on App Password bar form Sign in to Google section.

App Password

Step 4:

Select the app and device you want to generate the app password for. And enter a platform name and click on GENERATE button to generate new password.

Generated password

Finally copy your new generated password and save it your self also use it to your other device or app where you want to send SMTP email.

Step 5:

Now change password on Laravel .env file MAIL_PASSWORD value with new generated password.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Hope it will help you.

Categories
React Native

React Native – EventEmitter removeListener Method has been deprecated

Warning: Receiving warning on the console.

removeListener Method has been deprecated

EventEmitter.removeListener(‘appStateDidChange’, …): Method has been deprecated. Please instead use remove() on the subscription returned by EventEmitter.addListener.
EventEmitter.removeListener(‘appStateDidChange’, …): Method has been deprecated. Please instead use remove() on the subscription returned by EventEmitter.addListener.
EventEmitter.removeListener(‘appStateDidChange’, …): Method has been deprecated. Please instead use remove() on the subscription returned by EventEmitter.addListener.

React Native Version 0.65+, removeListener is depreciated. You can use remove() isntead of removeListener

Example of React Native useEffect:

Another way to escape this warning

If you are sure that the deprecated use is happening in a dependency you cannot control, it is possible to silence these warnings. In your App.tsx or somewhere else add LogBox on that screen.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Hope it will help you.

Categories
React Native

React Native – Take a Tour – App Tour – Tap Target View

React Native Take a Tour – App Tour – Tap Target View library. This library is a React Native bridge around android and ios app tour libraries. Supported RN >= 0.61

In this article I have discuses how to show Tap Target View on React Native project Function based component. Please follow below steps to implement example code for Tap Target View on function based component.

Android: KeepSafe/TapTargetView
An implementation of tap targets from Google’s Material Design guidelines on feature discovery.

iOS: aromajoin/material-showcase-ios
An elegant and beautiful tap showcase view for iOS apps based on Material Design Guidelines.

Run following command to Install

After install react-native-app-tour I call event emitter DeviceEventEmitter

Now, we need to import react-native-app-tour module with below code.

Now define appTourSequence

Now we need to configure props for app tour targets.

Now configure and add view targets to appTourSequence. Here is example for view ref props like “ref={ref => this.payoutListMenuRef = ref}

When finish app tour sequence, we can execute our own code by using below onFinishSequenceEvent event.

React Native App Tour View full Example code. You can move the code on your own created screen.

Categories
React Native

React Native – Deep linking example for Android and IOS

In this article I will discuses how to configure Deep Link on React Native application. React Native provides a Linking to get notified of incoming links. React Navigation can integrate with the Linking module to automatically handle deep links. Deep linking and universal links are gateway into your mobile application.

Configure Deep Link on React Native Application:

Very first, you want to specify a scheme URL for your app. If your app scheme is appname then a link to your app would be appname://

URL scheme for your app:

Open your Android app manifest android/app/src/main/AndroidManifest.xml you need to add following code between activity and queries tags section.

Now configure the native iOS app to open based on the appname:// URI scheme. You need to add the following lines to ios/AppName/AppDelegate.m file.

After this change you need to re-build app “react-native run-android” or “react-native run-ios”

App Links Configure:

Here is configure app initial route and others screens with query params.

Configure App Linking:

Here is full example code for setup on App screen.

Test Deep Linking on IOS and Android:

Categories
Magento 2

Magento error – Unable to apply data patch for module Magento_Theme. In Gd2.php line 72

In PatchApplier.php line 170: Unable to apply data patch Magento\Theme\Setup\Patch\Data\RegisterThemes for module Magento_Theme. Original exception message: Wrong file

In Gd2.php line 72: Wrong file

Finally Installation is complete 100% after done following changes:

Find validateURLScheme function in vendor\magento\framework\Image\Adapter\Gd2.php file. at line 96. Replace function with this: !file_exists($filename) Please find and change validateURLScheme function like below code.

Just add && !file_exists($filename)

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Hope it will help you.

Categories
Magento 2

Magento error – Could not validate a connection to Elasticsearch and Install using composer

Download Magento 2

Open SSH terminal on your server and run the following command to download and create new project. Previous post how to install Magento 2 on Windows XAMPP server.

Create The Database and Collect other information

Create new database and note Database name, database user name and database user password. Also site url, admin username, password, timezone and more. Run following command to install Magento 2.

Install/Setup Magento 2 by Command line

In SearchConfig.php line 81: Could not validate a connection to Elasticsearch. No alive nodes found in your cluster

If you got any error related with Elasticsearch then just disable some module related with Elasticsearch using run following command and again run install command.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Hope it will help you.

Categories
WordPress

How to fix invalid JSON response error in WordPress

Updating failed. The response is not a valid JSON response.

This error appears when edit and update your posts or pages on your WordPress website. You will see message saying “The response is not a valid JSON response” and updating that page would fail. In this article, I will show you how to fix the invalid JSON error in WordPress.

WordPress needs to communicate with the server while you are editing a post or page form WordPress admin and it getting responses from the web hosting server in the background. This response is in JSON format which is used to quickly transport data using JavaScript.

I getting this error when I move my wordpress website to another server.

Solution:

First please confirm your home and siteurl is ok on database wp_options table.

Please go to Settings => Permalinks page. From here, you need to review the WordPress permalink options. Please select “Post name” option form Permalink Settings and click on the Save Changes button to store your settings.

Permalink Settings

Also please confirm those code are available on the .htaccess file.

Now site is ready to edit post or page from WordPress admin.

Thank you for carefully read my article If you have any query please Leave your query on following comment section or contact with us. Hope it will help you.