PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, December 28, 2021

[FIXED] Facebook Conversions API - AuthorizationException (Invalid parameter)

 December 28, 2021     facebook-php-sdk, facebook-pixel, php     No comments   

Issue

While triggering the Purchase event after a successful transaction on the payment gateway and a redirection to the website, I'm getting the following error:

Fatal error: Uncaught FacebookAds\Http\Exception\AuthorizationException: Invalid parameter in /path/fb-business-sdk/vendor/facebook/php-business-sdk/src/FacebookAds/Http/Exception/RequestException.php:174 Stack trace: #0 /path/fb-business-sdk/vendor/facebook/php-business-sdk/src/FacebookAds/Http/Client.php(215): FacebookAds\Http\Exception\RequestException::create(Object(FacebookAds\Http\Response)) #1 /path/fb-business-sdk/vendor/facebook/php-business-sdk/src/FacebookAds/Http/Request.php(286): FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request)) #2 /path/fb-business-sdk/vendor/facebook/php-business-sdk/src/FacebookAds/Api.php(165): FacebookAds\Http\Request->execute() #3 /path/fb-business-sdk/vendor/facebook/php-business-sdk/src/FacebookAds/Api.php(214): FacebookAds\Api->executeRequest(Object(FacebookAds\Http\ in /path/fb-business-sdk/vendor/facebook/php-business-sdk/src/FacebookAds/Http/Exception/RequestException.php on line 174

Other events being triggered without any issues with a valid Pixel ID and a token.

$this->api = Api::init($pixel_id, null, $access_token);
$event = (new Event())
                ->setActionSource(ActionSource::WEBSITE)
                ->setEventName('Purchase')
                ->setEventTime(time())
                ->setEventSourceUrl($current_url)
                ->setUserData($user_data);
            
$events = array();
array_push($events, $event);
$request = $this->create_request($events);
// Execute the request
$response = $request->execute();

Solution

I had the same problem but found out that the reason to the exception is that a purchase event must have currency and value set.

$customData = (new CustomData())
        ->setCurrency('USD')
        ->setValue(10);

Then add the custom data to the event:

->setCustomData($customData)


Answered By - dannepanne
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing