FailedToCreateDynamicLink Error - Length of DynamicLink is over allowed limit - firebase

I have a Laravel REST project that uses the kreait/laravel-firebase package to use Firebase Dynamic Link. The REST API is being used by an ios app.
I'm having this error on logging in on other accounts/device. But no problem on some.
FailedToCreateDynamicLink
This is my code in creating the dynamic link:
$dynamicLinks = app('firebase.dynamic_links');
$action = CreateDynamicLink::forUrl($url)
->withIOSInfo(
IOSInfo::new()
->withBundleId(config('ios.bundle_id'))
->withAppStoreId(config('ios.app_store_id'))
->withFallbackLink('https://www.apple.com/ios/app-store/')
);
$link = $dynamicLinks->createDynamicLink($action);

Related

Auto-Login user into Wordpress site displayed in react-native <WebView> from Firebase

I have a react-native app running on expo with a login screen on my react-native application. When the user logs in, a JWT token is retrieved from Firebase and passed on to a which opens up a Wordpress Site. What I am trying to do is to automatically pass this JWT token to the and log them into the Wordpress site.
I tried several options, like installing the Firebase Authentication plugin by miniOrange, but I didn't know how to make this happen using the free version. I also tried using a custom script using the Code Snippets plugin and entering the below code. I had already installed php-jwt on my root folder in wordpress using compose.
require __DIR__ . '/vendor/autoload.php';
use \Firebase\JWT\JWT;
add_action('init', 'handle_jwt_token');
function handle_jwt_token() {
if (!empty($_GET['jwt_token'])) {
$jwt_token = sanitize_text_field($_GET['jwt_token']);
// Decode and verify the JWT token
$jwt_decoded = JWT::decode($jwt_token, YOUR_FIREBASE_PROJECT_ID, array('HS256'));
// Get the user data from the JWT token
$user_id = $jwt_decoded->sub;
$user_email = $jwt_decoded->email;
$user_name = $jwt_decoded->name;
// Log the user into Wordpress
$user = get_user_by('email', $user_email);
if (!$user) {
// Create a new Wordpress user if they don't already exist
$user_id = wp_create_user($user_email, wp_generate_password(), $user_email);
wp_update_user(array(
'ID' => $user_id,
'display_name' => $user_name,
));
}
wp_set_current_user($user->ID);
wp_set_auth_cookie($user->ID);
wp_redirect("https://homepage_url.com");
exit;
}
}
I just ended up getting an error
Uncaught Error: Failed opening required '/var/www/vhosts/test.com/html/wp-content/plugins/code-snippets/php/admin-menus/vendor/autoload.php' (include_path='.:') in /var/www/vhosts/test.com/html/wp-content/plugins/code-snippets/php/admin-menus/class-edit-menu.php(253)
My question is, are there any options available for me to achieve this? Thank you for your time in reading this!
You will able to achieve it with this extension.
https://firebase-wordpress-docs.readthedocs.io/en/latest/extensions/jwt.html#remote-authentication-via-url
It will require you generate a token on your React Native and pass it to the WebView, after that WordPress can handle the auto login.
You can try it here: https://dn-wp-autologin.web.app/

Google Analytics API using PHP with service account

I have been searching and looking this up for two days now and can't figure out where I am going wrong. I am attempting to pull data from my google analytics account using php. I have followed all the steps to set up a service account and downloaded the JSON file. Here is the code I am using:
// Load the Google API PHP Client Library
require_once ('/google-api-php-client-1-master/src/Google/autoload.php');
$KEY_FILE_LOCATION = '/inc/ac_key.json';
// Create and configure a new client object.
$client = new Google_Client();
$client->setApplicationName("Hello Analytics Reporting");
$client->setAuthConfig($KEY_FILE_LOCATION);
$client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
$analytics = new Google_Service_Analytics($client);
function getResults($analytics, $profileId) {
// Calls the Core Reporting API and queries for the number of sessions
// for the last seven days.
return $analytics->data_ga->get(
'ga:' . $profileId,
'30daysAgo',
'today',
'ga:pageviews'
);
}
$profile = $r['google_analytics'];
$results = getResults($analytics, $profile);
$month = date('n');
$year = date('Y');
$results->setMonth($month,$year);
$visits = $results->getVisitors();
$views = $results->getPageviews();
/* build tables */
if(count($visits)) {
foreach($visits as $day=>$visit) {
$flot_datas_visits[] = '['.$day.','.$visit.']';
$flot_datas_views[] = '['.$day.','.$views[$day].']';
}
$flot_data_visits = '['.implode(',',$flot_datas_visits).']';
$flot_data_views = '['.implode(',',$flot_datas_views).']';
}
I am getting an error for an invalid client_secret.json file but I am attempting to authenticate using a service account so I am not sure what is going on here. I am then attempting to plot the data in a flot table but I am not worried about that part yet as I am still trying to get through this first hurdle. Any help would be appreciated!
I'm not quite up-to-date with the Google PHP API client, but apparently there are different versions on offer - when I cloned the repo I got the version that you app use and I did not get it to work with my credentials file. I then installed the current version of the library via composer:
composer require google/apiclient:^2.0
I was then able to access a Google Analytics with the following code:
<?php
include_once __DIR__ . '/vendor/autoload.php';
date_default_timezone_set('America/Los_Angeles');
$client = new Google_Client();
$client->setAuthConfig('/path/to/credentials.json');
$client->setApplicationName("Client_Library_Examples");
$client->setScopes(['https://www.googleapis.com/auth/analytics.readonly']);
$service = new Google_Service_Analytics($client);
function getResults($service, $profileId) {
return $service->data_ga->get(
'ga:' . $profileId,
'30daysAgo',
'today',
'ga:pageviews'
);
}
$profile= "80493610";
$results = getResults($service, $profile);
print_r($results);
With a bit of poking around I managend to get an instance of the analytics service with the old version from your example. Apparently you have to use the loadServiceAccountJson function rather than setAuthConfig
<?php
// Load the Google API PHP Client Library
require_once ('google-api-php-client/src/Google/autoload.php');
$KEY_FILE_LOCATION = '/path/to/credentials.json';
// Create and configure a new client object.
$client = new Google_Client();
$client->setApplicationName("Hello Analytics Reporting");
$scopes = ['https://www.googleapis.com/auth/analytics.readonly'];
$client->loadServiceAccountJson($KEY_FILE_LOCATION, $scopes);
$analytics = new Google_Service_Analytics($client);
print_r($analytics);

Evernote PHP sdk integration with Symfony2

I am using this documentation to set up Evernote cloud sdk php into Symfony2 :
https://github.com/evernote/evernote-cloud-sdk-php/blob/master/documentation/Getting_Started.md
As they say, I installed it first with composer.
Then I am using this code
$sandbox = true;
$oauth_handler = new \Evernote\Auth\OauthHandler($sandbox);
$key = '%key%';
$secret = '%secret%';
$callback = 'http://host/pathto/evernote-cloud-sdk-php/sample/oauth/index.php';
$oauth_data = $oauth_handler->authorize($key, $secret, $callback);
echo "\nOauth Token : " . $oauth_data['oauth_token'];
I changed the parameters with mine, but the problem is inside Evernote\Auth\OauthHandler :
https://github.com/evernote/evernote-cloud-sdk-php/blob/master/src/Evernote/Auth/OauthHandler.php
The lib is using the function header(location: ...);
And the function is not executing.
I guess Symfony2 is not allowing the usage of this function.
Is there a way to force it ?
Or how can I change it in a good way (and to be able to push on my git repository) ?
Thanks,

Which PHP Script File is needed for ical() class in Google Calendar PHP API v3

I am getting an error in a PHP script I am building:
Fatal error: Class 'ical' not found in /home/abc/public_html/app/mods/googleCalendar_3.0/cache_events.php on line 74
Here is a snippet from my script file:
define('CLIENT_ID', 'ASDLJJLDSJLASDJLajdl;jdsljkASD;LKJASDLKJASD.apps.googleusercontent.com');
require_once('autoload.php'); // 2014-11-24 part of /usr/local/lib/php/google-api-php-client
require_once('/usr/local/lib/php/google-api-php-client/src/Google/Client.php'); // 2014-11-25
require_once('/usr/local/lib/php/google-api-php-client/src/Google/Service/Calendar.php'); // 2014-11-25
$ical = new ical('https://www.google.com/calendar/ical/CLIENT-ID/public/basic.ics');
$eventListArray = array_filter($ical -> events(), "locationfilter");
$eventCount = count($eventListArray);
print_r($eventListArray); echo "<br>";
echo "Event Count:" . $eventCount;echo "<br>";
exit;
I am simply trying to retrieve all events in my public calendar
Notes:
Calendar is publicly viewable
Just to make sure, I added my Auth & API's > Credentials > Service Account > Email Address to it just to be safe
If you want to use a service account your code is off quite a bit. I cant test this code my local webserver is acting up but it should be close you may have to tweek the $service->Events->list(); part it was kind of a guess. Make sure that you have the Service account email address added as a user on the calendar in question and it should work.
session_start();
require_once 'Google/Client.php';
require_once 'Google/Service/Calendar.php';
/************************************************
The following 3 values an befound in the setting
for the application you created on Google
Developers console. Developers console.
The Key file should be placed in a location
that is not accessable from the web. outside of
web root. web root.
In order to access your GA account you must
Add the Email address as a user at the
ACCOUNT Level in the GA admin.
************************************************/
$client_id = '1046123799103-nk421gjc2v8mlr2qnmmqaak04ntb1dbp.apps.googleusercontent.com';
$Email_address = '1046123799103-nk421gjc2v8mlr2qnmmqaak04ntb1dbp#developer.gserviceaccount.com';
$key_file_location = '629751513db09cd21a941399389f33e5abd633c9-privatekey.p12';
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$key = file_get_contents($key_file_location);
// seproate additional scopes with a comma
$scopes ="https://www.googleapis.com/auth/calendar";
$cred = new Google_Auth_AssertionCredentials(
$Email_address,
array($scopes),
$key
);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$service = new Google_Service_Calendar($client);
// you should only need to do this once print this and you will
// find the calendarId for the one you are looking for.
$calendars = $service->calendarList->list();
$events = $service->events->list($yourCalendarID);
Note: all you need is the Google Dir you can remove everything above that you dont really need it. Code was edited from the only tutorial i have that shows this in PHP.

Cannot Authenticate Salesforce in a Wordpress Plugin

I'm getting an error (INVALID_SESSION_ID) when trying to send an authenticated GET request to Salesforce.com.
Here is the plug-in in its entirety, which basically just outputs the body of the REST response to whatever page has the [MembershipTables] shortcode:
if (!class_exists('WP_Http')) {
include_once(ABSPATH . WPINC . '/class-http.php');
}
// This is obviously the real username
$username = 'xxxx#xxxx.xxx';
// And this is obviously the real password concatonated with the security token
$password = 'xxxxxxxxxxxxxx';
function getMembershipTables() {
$api_url = 'https://na15.salesforce.com/services/apexrest/directory';
$headers = array('Authorization' => 'Basic ' . base64_encode("$username:$password"));
$args = array('headers' => $headers);
$request = new WP_Http;
$result = $request->request($api_url, $args);
$body = $result['body'];
echo "$body";
}
add_shortcode( 'MembershipTables', 'getMembershipTables' );
I should note that I can successfully hit this endpoint with Curl, though I use a session token I get from Salesforce using the old SOAP API to keep it equivalent (i.e., no client id/secret).
Am I doing something wrong with WP_Http? Or cannot I not authenticate a salesforce.com request using basic auth?
Thanks.
The salesforce API does not support Basic authentication, you need to call it with a sessionId. You can obtain a sessionId by various methods include interactive & programatic OAuth2 flows, and via a Soap login call.
Basis Interactive had a similar problem to solve. When I worked on the project I opted to to call the SalesForce CRM via the preset form plugin and a custom JS Cookie PHP Wordpress Plugin. We had this problem easily resolved by developing custom calls to SalesForce CRM via a getRequest in PHP passing data to the SalesForce CRM.
Test Site in Use:
http://newtest.medullan.com/wp/?page_id=3089
Here is the code and recycle the logical queries
Download Link:
http://basisinteractive.net/webdesign.html#wordpress

Resources