I get this error when I try to run my app locally via xampp. Just to note, I generated code using quick start from developers.facebook so there shouldnt be errors within the code itself.
Notice: Use of undefined constant STDOUT - assumed 'STDOUT' in C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Logger\CurlLogger.php on line 83
Warning: fwrite() expects parameter 1 to be resource, string given in C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Logger\CurlLogger.php on line 182
Fatal error: Uncaught exception 'FacebookAds\Http\Exception\AuthorizationException' with message '(#100) Filtering field delivery_info is invalid. Please refer to the document https://developers.facebook.com/docs/marketing-api/insights for valid filters.' in C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Exception\RequestException.php:144 Stack trace: #0 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Client.php(215): FacebookAds\Http\Exception\RequestException::create(Object(FacebookAds\Http\Response)) #1 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Request.php(282): FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request)) #2 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Api.php(162): FacebookAds\Http\Request->execute() #3 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Api.php(204): FacebookAds\Api->executeRequest(Object(FacebookAds\Http\Request)) #4 C:\xampp\htdocs\working\vendor\facebo in C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Exception\RequestException.php on line 144
I'm starting to suspect that I got the wrong files from the composer. or there might be a problem with my setup. The contents of my composer.json just before I ran composer.phar was
{
"require": {
"facebook/php-sdk-v4" : "~5.0",
"facebook/php-ads-sdk": "2.10.*"
}
}
I'm going to attach the code below just in case you guys want to look at it as well. The only thing that I modified there is adding the app_id since it was not included from the generated code.
<?php
require __DIR__ . '/vendor/autoload.php';
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\AdsInsights;
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;
$app_id = '274807576345457';
$access_token = 'EAAD575ZC4O3EBAChoTmxC0nwdbvjXLRUKGGXgmZA6HZBFjmKZB6F3olMIe2mG2dgQSb9SudtN7EeeO8gzo7zgFZB0EHZAwTrg4wsIKsJxB3bhw5fonZC3YCZA0C4InaCSOgW42i4PswQa3BZCctMZBYTh94TwGLxGg8gZAZAj4zZC5PfgXl0kw6eOuxW4g1L41NOwtRDGS7O7FsJZBWZCM0IAe00WSf';
$ad_account_id = 'act_113902719358005';
$app_secret = 'aeb42f19e0f33f0937c023fff12909c4';
$api = Api::init($app_id, $app_secret, $access_token);
$api->setLogger(new CurlLogger());
$fields = array(
'cost_per_result',
'cost_per_total_action',
'cpm',
'cpp',
'frequency',
'impressions',
'impressions_auto_refresh',
'impressions_gross',
'reach',
'relevance_score:score',
'relevance_score:positive_feedback',
'relevance_score:negative_feedback',
'result_rate',
'results',
'social_impressions',
'social_reach',
'spend',
'today_spend',
'total_actions',
'total_unique_actions',
'actions:video_view',
'video_10_sec_watched_actions:video_view',
'delivery',
);
$params = array(
'level' => 'campaign',
'filtering' => array(array('field' => 'delivery_info','operator' => 'IN','value' => array('active','limited'))),
'breakdowns' => array(),
'time_range' => array('since' => '2017-09-28','until' => '2017-09-29'),
);
echo json_encode((new AdAccount($ad_account_id))->getInsights(
$fields,
$params
)->getResponse()->getContent(), JSON_PRETTY_PRINT);
if comment this part
[json_encode((new AdAccount($ad_account_id))->getInsights(
$fields,
$params
)->getResponse()->getContent(), JSON_PRETTY_PRINT);]
; the error stop.
if make [var_export((new AdAccount($ad_account_id));] show full array
I experienced the exact same error. I believe (in my case) this was because I was also using an older PHP version (5.6) resulting in some compatibility issues.
I solved this by changing the version of php-ads-sdk from 2.8 to "8.*" (or change it to any recent version according to when you are reading this solution) in composer.json.
Then call sudo composer update in your terminal
Related
I'm trying out the ActiveCollab API for my first time. I had to use StackOveflow to figure out how to get the API token since the docs don't tell me this.
Below is my code:
/* GET INTENT */
$url = 'https://my.activecollab.com/api/v1/external/login';
$fields = array(
'email' => "email#email.com",
'password' => "****"
);
$intent = curl_post_connector($url, $fields);
$intent = $intent->user->intent;
/* GET TOKEN */
$url = 'https://app.activecollab.com/my_app_id/api/v1/issue-token-intent';
$fields = array(
'intent' => $intent,
'client_name' => 'My App Name',
'client_vendor' => 'My Company Name'
);
$token = curl_post_connector($url, $fields);
$token = $token->token;
Everything above works and get's the token properly. What I find really weird is that I have to use API v1 to get this, and the docs on ActiveCollab's site don't mention any URL for API v5. It seems like this is the approach everything is taking here on StackOverflow.
Now with the token, I try to get my list of projects:
/* GET PROJECT */
$url = 'https://app.activecollab.com/my_app_id/api/v1/users';
$headers = array (
"X-Angie-AuthApiToken" => $token
);
$projects = curl_get_connector($url, $headers);
var_dump($projects);
But this does not work. There is no error returned - it instead returns an array of languages for some reason! I don't want to paste the massive json object here, so instead I'll link you to a photo of it: https://www.screencast.com/t/7p5JuFB4Gu
UPDATE:
When attempting to use the SDK, it works up until I try getting the token (which is just as far as I got without the SDK). I'm getting Server Error 500, and when looking at the logs, it says:
/home/working/public_html/ac/index.php(21): ActiveCollab\SDK\Authenticator\Cloud->issueToken(123456789)
#1 {main}
thrown in /home/working/public_html/ac/SDK/Authenticator/Cloud.php on line 115
This is line 115 of Cloud.php:
throw new InvalidArgumentException("Account #{$account_id} not loaded");
I honestly don't think I did anything wrong... there must be something wrong with my account ID.
Just for kicks, I commented out that line, and the error disappears and the page loads fine - except now I have no token...
an advanced thank you for taking time answering this.
I would like to retrieve all of my campaign list in facebook marketing API.
this is my code:
use FacebookAds\Object\AdUser;
use FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdAccountFields;
use FacebookAds\Object\Campaign;
use FacebookAds\Object\AdCampaign;
use FacebookAds\Object\Fields\CampaignFields;
use FacebookAds\Object\Fields\AdCampaignFields;
use FacebookAds\Object\Fields\AdsInsightsFields;
use FacebookAds\Object\Fields\AdSetFields;
$account = new AdAccount($account_id);
$params = array(
'time_interval' => array(
'day_start' => array('year' =>'2015', 'month'=> '5', 'day'=>'1'),
'day_stop' => array( 'year'=>'2015', 'month'=>'5', 'day'=>'31')
),
'limit' => 500,
);
$fields = array(
AdCampaignFields::NAME, /* <--- this is the error */
AdCampaignFields::OBJECTIVE,
AdCampaignFields::STATUS,
);
$campaigns = $account->getAdCampaigns($fields,$params);
print_r($campaigns);
Now there are no result shown instead there's an error:
[14-Feb-2017 01:26:55 UTC] PHP Fatal error: Class 'FacebookAds\Object\Fields\AdCampaignFields' not found in /home/rbadmin17/public_html/test_17/index.php on line 98
I already call the "AdCampaignFields" and still it says Class not found.
Thanks for the help...
Your code looks correct but the class AdCampaignFields doesn't yet exist in the up to date SDK and was replaced by CampaignFields class (which isn't actually needed for your code).
Your code should work just by removing the line :
use FacebookAds\Object\Fields\AdCampaignFields;
Edit: in fact some examples of the FB doc are deprecated. Just take a look in the SDK folders to see by yourself when you get this kind of error. Sometimes it's just a class name which have been changed.
I created a code to use Amazon S3 using this composer component:
https://github.com/2amigos/yii2-resource-manager-component
This worked very well.
But I changed my server and when I upload a image to Amazon S3 I received this error:
PHP Fatal Error – yii\base\ErrorException
Class 'Aws\S3\Enum\CannedAcl' not found
I did not change anything of code, I dont understand why this error, I cant find a solution
How can I fix it?
This is the complete error :
PHP Fatal Error – yii\base\ErrorException
Class 'Aws\S3\Enum\CannedAcl' not found
1. in /opt/app-root/src/admapps/vendor/2amigos/yii2-resource-manager-component/AmazonS3ResourceManager.php at line 78
69707172737475767778798081828384858687 * #return \Guzzle\Service\Resource\Model
*/
public function save($file, $name, $options = [])
{
$options = ArrayHelper::merge([
'Bucket' => $this->bucket,
'Key' => $name,
'SourceFile' => $file->tempName,
'ACL' => CannedAcl::PUBLIC_READ // default to ACL public read
], $options);
$this->getClient()->putObject($options);
}
/**
* Removes a file
* #param string $name the name of the file to remove
* #return boolean
*/
2. in /opt/app-root/src/admapps/vendor/yiisoft/yii2/base/InlineAction.php at line 55 – app\controllers\BeersController::actionUploadlogobeer()
3. in /opt/app-root/src/admapps/vendor/yiisoft/yii2/base/InlineAction.php at line 55 – call_user_func_array:{/opt/app-root/src/admapps/vendor/yiisoft/yii2/base/InlineAction.php:55}()
4. in /opt/app-root/src/admapps/vendor/yiisoft/yii2/base/Controller.php at line 154 – yii\base\InlineAction::runWithParams()
5. in /opt/app-root/src/admapps/vendor/yiisoft/yii2/base/Module.php at line 454 – yii\base\Controller::runAction()
6. in /opt/app-root/src/admapps/vendor/yiisoft/yii2/web/Application.php at line 87 – yii\base\Module::runAction()
7. in /opt/app-root/src/admapps/vendor/yiisoft/yii2/base/Application.php at line 375 – yii\web\Application::handleRequest()
8. in /opt/app-root/src/admapps/web/index.php at line 13 – yii\base\Application::run()
78910111213require(__DIR__ . '/../vendor/autoload.php');
require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php');
require(__DIR__ . '/../helpers/Utils.php');
$config = require(__DIR__ . '/../config/web.php');
(new yii\web\Application($config))->run();
Posted by Bizley
This extension uses "aws/aws-sdk-php": "2.5.2" and it's very old (at GitHub version 3.18 is latest). AWS said they've removed CannedAcl in version 3 so it should not make impact on 2.5.2 (it is present in 2.5.2). Anyway there is the same issue reported about this github.com/2amigos/yii2-resource-manager-component/issues/10 – Bizley
I'm trying to test Stripe Checkout on my virtual server but when i try return this error:
Fatal error: Class 'Stripe\Customer' not found in
/home/user/public_html/charge.php on line 8
As suggested here I verified if the file ./config.php was existing with:
var_dump(file_exists("./config.php"));
It returns bool(true) being a PhP beginner im not sure what i'm doing wrong.
charge.php
<?php
require_once('./config.php');
var_dump(file_exists("./config.php"));
$token = $_POST['stripeToken'];
$customer = \Stripe\Customer::create(array(
'email' => 'customer#example.com',
'source' => $token
));
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => 2000,
'currency' => 'usd'
));
echo '<h1>Successfully charged $20.00!</h1>';
?>
config.php
<?php
require_once('vendor/stripe/init.php');
$stripe = array(
secret_key => getenv('sk_test_PidozakrX1NIEf8YM9TBDMl8'),
publishable_key => getenv('pk_test_pCzekEHR4Io5YFJhrzFE7Koe')
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>
Directory:
>public_html
>vendor
>stripe
>lib
>Charge.php
>Customer.php
>Stripe.php
UPDATE
Okay so with changes suggested by Matthew getting new error. But i'm not sure where should I set the API key Stripe::setApiKey(<API-KEY>)? It's aleady set in config.php...
Fatal error: Uncaught exception 'Stripe\Error\Authentication' with
message 'No API key provided. (HINT: set your API key using
"Stripe::setApiKey()".in
/home/user/public_html/vendor/stripe/lib/ApiRequestor.php:127 Stack
trace: #0
/home/user/public_html/vendor/stripe/lib/ApiRequestor.php(59):
Stripe\ApiRequestor->_requestRaw('post', '/v1/customers', Array,
Array) #1
/home/user/public_html/vendor/stripe/lib/ApiResource.php(115):
Stripe\ApiRequestor->request('post', '/v1/customers', Array, Array) #2
/home/user/public_html/vendor/stripe/lib/ApiResource.php(155):
Stripe\ApiResource::_staticRequest('post', '/v1/customers', Array,
NULL) #3 /home/user/public_html/vendor/stripe/lib/Customer.php(37):
Stripe\ApiResource::_create(Array, NULL) #4
/home/user/public_html/charge.php(9): Stripe\Customer::create(Array)
5 {main} thrown in /home/user/public_html/vendor/stripe/lib/ApiRequestor.php on line 127
I'm not sure but it looks like due to the composer, If you haven't check path yet , please first look them in composer.json
{
"autoload": {
"psr-0": {
"Sub-folder/path": "class's parent directory "
}
}
NOTE: If the problem occurs due to this one , You should re-install websocketOR you can arrange path to this structure
Yesterday I emailed stripe support. I could of never figured the answer out...! So turns out the issue here is the way I've setup the API keys in config.php. This code will not do what we think... It's trying to retrieve an environment variable set with the variable name as the API key which will just return an empty string...
config.php
<?php
require_once('vendor/stripe/init.php');
$stripe = array(
secret_key => getenv('sk_test_PidozakrX1NIEf8YM9TBDMl8'),
publishable_key => getenv('pk_test_pCzekEHR4Io5YFJhrzFE7Koe')
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>
should be
<?php
require_once('vendor/stripe/init.php');
$stripe = array(
secret_key => ('sk_test_PidozakrX1NIEf8YM9TBDMl8'),
publishable_key => ('pk_test_pCzekEHR4Io5YFJhrzFE7Koe')
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>
Basically, just remove getenv after each arrow. For me it works! The customer is created and the amount is charged! Nothing fancy. Simple solution.
I'm running php-resque together with Laravel 3 on Ubuntu 12.04.
Problem: When a job is enqueued in resque, I get the following error:
Unhandled Exception
Message:
Constant CRLF already defined
Location:
/var/www/dev/vendor/chrisboulton/php-resque/lib/Redisent/Redisent.php on line 10
What does the error mean and how can we solve it?
PHP
// Enqueue in Resque
$data = array(
'name' => $name,
'email' => $email,
'created_at' => DB::raw('NOW()')
);
Resque::enqueue('queue', 'exampleWorker', $data);
However when I try to enqueue a job using artisan, it works!
Task
class Queue_Task
{
public function run()
{
// Autoload composer vendors.
require path('composer').DS.'autoload.php';
$args = array('name' => 'John Smith');
Resque::enqueue('MyAppName', 'ExampleWorker', $args);
echo "Resque job queued.\n";
return;
}
}
Output
PHP Notice: Constant CRLF already defined in /var/www/dev/vendor/chrisboulton/php-resque/lib/Redisent/Redisent.php on line 10
Notice: Constant CRLF already defined in /var/www/dev/vendor/chrisboulton/php-resque/lib/Redisent/Redisent.php on line 10
Resque job queued.
It's a guess, but I'd say in /var/www/dev/vendor/chrisboulton/php-resque/lib/Redisent/Redisent.php there's a second define('CRLF', 'something') on line 10 that should probably be commented out if you want these two pieces of software to work together.