Model\User not found - php

I am trying to retrieve information on Users using the Microsoft Graph Library for PHP.
I can see that in GraphResponse.php, my $result is filled with correct data but the code does not find the Model\User-class.
$user = $graph->createRequest("GET", "/users")
->setReturnType(Model\User::class)
->execute();
Since I am not familiar with this autoload-thing, I am stuck. Any help appreciated.
Is there any better documentation for this subject???

It appears you're experiencing some troubles with installing msgraph-sdk-php package and that's the reason why Model\User type could not be resolved in your case. If you are following the official Getting Started documentation, there is a typo regarding package name in Installation section:
{
"require": {
"Microsoft/Graph": "^1.0"
}
}
and while installing you should get the error like this
The requested package microsoft/graph could not be found in any
version, there may be a typo in the package name.
Instead of Microsoft/Graph the valid name should be microsoft/microsoft-graph, for example:
{
"require": {
"microsoft/microsoft-graph": "^1.6"
}
}
Once the package is installed successfully, the minimal example for retrieving users could look like this:
require_once './vendor/autoload.php';
use \Microsoft\Graph\Graph;
$accessToken = "--YOUR-ACCESS-TOKEN-GOES-HERE--";
$graph = new Graph();
$graph->setAccessToken($accessToken);
$user = $graph->createRequest("GET", "/users")
->setReturnType(\Microsoft\Graph\Model\User::class)
->execute();

Related

What is the proper way to use plaid with php/laravel?

I am using
travoltron/plaid
for laravel(5.6).
Plaid package version is "travoltron/plaid": "^2.0" and guzzle version is "guzzlehttp/guzzle": "6.0".
I have followed the documentation and placed
PLAID_CLIENT_ID=**********************
PLAID_SECRET=**************************
in .env file.
now when i use
use Plaid;
public function auth() {
$authUser = Plaid::addAuthUser('user_good', 'pass_good', null, 'chase');
return $authUser;
}
it show me an error "count(): Parameter must be an array or an object that implements Countable".
If my approach regarding using this package is wrong please suggest me better way
or guide me.
So, the Plaid package you're using is from an unofficial (community-maintained) package that hasn't been updated in 3 years.
While we can't really support community packages, I'd at least suggest using a more actively maintained library, like this one by TomorrowIdeas: https://github.com/TomorrowIdeas/plaid-sdk-php

Getting the Google Client to work in Lumen

I am trying to get the google api client for php to work in Lumen, however trying to create a client results in my api to give a 'Oops, something went wrong' error with no further useful information.
I think it is something to do with the way im trying to import the google api client into Lumen, i used composer to install it. But i am not sure if i am using the right thing for Lumen. If i change my require_once it would state that it could not find the 'autoload.php' in the current path. I've also tried the composer update -vvv
The Google folder is present in my vendor folder, and the composer.json also has a entry for the google/apiclient
"require": {
"php": ">=7.1.3",
"google/apiclient": "2.0",
"laravel/lumen-framework": "5.8.*"
},
<?php
namespace App\Http\Controllers;
require_once dirname(__DIR__).'\..\..\vendor\autoload.php';
use App\Author;
use Illuminate\Http\Request;
class AccessController extends Controller
{
private function getToken()
{
$credentialsFilePath = 'service_account.json';
$client = new Google_Client();
$client->setAuthConfig($credentialsFilePath);
$client->addScope('https://googleapis.com/auth/analytics.readonly');
$client->setApplicationName("GoogleAnalytics");
$client->refreshTokenWithAssertion();
$token = $client->getAccessToken();
$accessToken = $token['access_token'];
return $accessToken;
}
public function showAccess()
{
$at = getToken();
return response('Token: ');
}
}
As you can see im trying to get the service account access token from a json that is saved at the server (no problems). but whenever the line $client = new Google_Client();
is called, i get the 'woops, something went wrong' error from Lumen
It appears i forgot the use Google_Client; Pretty simple but something i completely overlooked.

Call to undefined method Maatwebsite\Excel\Excel::create() - laravel 5.6

I am using Maatwebsite/Excel in my application and when i get the error
Call to undefined method Maatwebsite\Excel\Excel::create()
from one of my controllers. I am using laravel 5.6 and i have followed the documentation strictly and other very few related discussions online to solve this, but i still get the error.
How do i solve this error please
app.php
'provider' => 'Maatwebsite\Excel\ExcelServiceProvider',
'alias' => 'Excel'=> 'Maatwebsite\Excel\Facades\Excel',
Controller
$cl = ClassModel::Select('name')->where('code',$input->class)->first();
$input->class=$cl->name;
$fileName=$input->class.'-'.$input->section.'-'.$input->session.'-'.$input->exam;
// return $students;
Excel::create($fileName, function($excel) use($input,$subjects,$students) {
$excel->sheet('New sheet', function($sheet) use ($input,$subjects,$students) {
$sheet->loadView('app.excel',compact('subjects','input','students'));
});
})->download('xlsx');
You are using 2.* syntax while using 3.* package. Please refer to the correct documentation over here: https://laravel-excel.maatwebsite.nl/docs/3.0/export/basics
Try to decrease the version using :
composer require "maatwebsite/excel=2.1.0"
There have been many changes in the new version of the package.
In your composer.json file inside the require array replace your package with this:
"maatwebsite/excel": "~2.1.0",
and then run composer update
This should work fine.
Please switch to version 2*
Version 3.0 of that package doesn't handle imports yet. Release date for this feature is unknown. See this post for more details: maatwebsite
I have worked it around but I know it's not a perfect solution. It will really help you if you only have concerns with the uploading not adjusting Crudbooster features.
I removed the extra features from the importing screen of the Crudbooster by applying the following CSS in the crudbooster-controller.
$this->style_css = "ul.nav li:not(:first-child) {
display: none;
}";
I copied the getImportData() method from Crudbooster CBController and overridden it in the crudbooster-controller by the following code.
//PHP
//By the way, you can still create your own method in here... :)
public function getImportData()
{
$this->cbLoader();
$data['page_menu'] = Route::getCurrentRoute()->getActionName();
$data['page_title'] = 'Import Data';
if (request('file') && ! request('import')) {
$file = base64_decode(request('file'));
$file = storage_path('app/'.$file);
$data = Excel::import(new ProductImport, $file);
CRUDBooster::redirect('/admin/products', cbLang("alert_add_data_success"), 'success');
}
return view('crudbooster::import', $data);
}
Importing is working fine now

Using AdWords BatchJob in PHP

I'm trying to get new BatchJob (https://developers.google.com/adwords/api/docs/guides/batch-jobs) up and running, however missing one part.
Docs says:
The good news is that your client library of choice will have a
utility that handles constructing and sending the request for you. The
example below uses the BatchJobHelper utility from the Java client
library.
However PHP library is missing that Helper and any method that should do that...
Anyone had any luck sending request to API using BatchJob? I can't find any working example anywhere.
Thanks!
In the branch experimental they are rewriting the API. It seems that the BatchJobHelper is missing still (current day of write this), see my issue in github requesting it.
For get BatchJobs you should use the BatchJobService class, which is instantiated from the adword service. This is a example snippet:
$batch_job_service = $adWordsServices->get($session, 'BatchJobService', 'v201605', 'cm');
try
{
/** #var BatchJobReturnValue $result */
$result = $batch_job_service->mutate($operations);
}
catch(ApiException $e)
{
echo $e->getMessage() . PHP_EOL;
}
if(!empty($result) && $result instanceof Google\AdsApi\AdWords\v201605\cm\BatchJobReturnValue)
{
$batch_job = reset($result->getValue());
}
else
{
echo 'Result is empty or no valid';
}
If you are using composer to load the new v201603 version of adwords you will need to also adjust your composer file to map the utils since they are duplicated across the other versions for some reason.. Not sure why they did this. you should be able to find the class you need with the following path. Hope this helps.
{
"require": {
"googleads/googleads-php-lib": "8.3.0"
},
"autoload": {
"classmap": [
"vendor/googleads/googleads-php-lib/src/Google/Api/Ads/AdWords/Util/v201601"
]
}
}

Fatal error: Class 'Stripe\Stripe_Charge' not found in

This is the code I'm using.
<?php
require_once('init.php');
if ($_POST) {
\Stripe\Stripe::setApiKey("xxxxxxxxxxxxx");
$error = '';
$success = '';
try {
if (!isset($_POST['stripeToken']))
throw new Exception("The Stripe Token was not generated correctly");
$charge = \Stripe\Stripe_Charge::create(array("amount" => 100, //995
"currency" => "eur",
"card" => $_POST['stripeToken']));
$success = 'Your payment was successful.';
}
catch (Exception $e) {
$error = $e->getMessage();
}
}
?>
Why am I getting the error
"Fatal error: Class 'Stripe\Stripe_Charge' not found in"
I was pulling my hair out on this one as well, but finally found the solution.
From what I found out older versions of PHP (<5.3) did not use namespaces. To get around this PSR-0* converted underscores to directory names. This created a messy interface for Composer. Now with PHP 5.3 and higher namespaces have been added. Composer now uses PSR-4 which supports namespaces but does not convert underscores to directories. Therefore, if you are using the newer preferred PSR-4, you need to use the new method. Therefore, your line:
$charge = \Stripe\Stripe_Charge::create(...);
needs to become:
$charge = \Stripe\Charge::create(...);
You can double check to see what version of PSR your Stripe module is using by opening the /vendor/stripe/stripe-php/composer.json file. Mine shows:
"autoload": {
"psr-4": { "Stripe\\" : "lib/" }
},
which clearly states that I am using PSR-4.
Here is some good reading on the subject: https://mattstauffer.co/blog/a-brief-introduction-to-php-namespacing
*PSR stands for PHP Standards Recommendation
I discovered that neither UsageRecord.php nor UsageRecordSummary.php were available in my stripe-php/lib directory and likewise not initiated in my stripe-php/init.php. I went and grabbed them from https://github.com/stripe/stripe-php/blob/master/lib/
Using Composer to install. adam-paterson/oauth2-stripe. Not sure if this is missing there.

Categories