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

Saturday, February 26, 2022

[FIXED] Facebook Business SDK for PHP - Unknown Components

 February 26, 2022     facebook-business-sdk, facebook-php-sdk, php     No comments   

Issue

I am trying to access a user via the Facebook Business PHP SDK but I am getting the following error:

USER_ID is just a placeholder for my FB ID.

FacebookAds\Http\Exception\AuthorizationException
Unknown path components: /USER_ID

The code I am using is as follows:

Again the APP_ID, APP_SECRET, USER_ACCESS_TOKEN, AND USER_ID are all placeholders but are correct in my code.

    $api = Api::init(APP_ID, APP_SECRET, USER_ACCESS_TOKEN);
    $api->setLogger(new CurlLogger());
    $api->setDefaultGraphVersion('v13.0');

    $fbuser =  new \FacebookAds\Object\User(USER_ID);

    die(var_dump($fbuser->getSelf()));

This is the first step of what I am trying to achieve, I need to access the ad accounts associated with a user but when I call the following:

  die(var_dump($fbuser->getAdAccounts()));

I get the same error:

FacebookAds\Http\Exception\AuthorizationException
Unknown path components: /USER_ID/adaccounts

When call the graph API directly via cURL or the graph api explorer. I get a list of ad accounts as intended, so i am not sure sure what the problem is.

Example:

https://graph.facebook.com/v13.0/USER_ID/adaccounts?access_token=USER_ACCESS_TOKEN

I have seen some old issues on here relating to the version of the API being wrong, but i have tried both 13.0 and v13.0 still no luck.

Would appreciate any help as i would prefer to use the SDK then writing my own wrapper.


Solution

After further tinkering, it does indeed look like it's an issue with the version of the graph.

The version needs to be set as 13.0, not v13.00.

Working code to get ad accounts if anybody else has this issue:

    $api = Api::init(APP_ID, APP_SECRET, USER_ACCESS_TOKEN);
    $api->setLogger(new CurlLogger());
    $api->setDefaultGraphVersion('13.0');

    $fbuser = new \FacebookAds\Object\User();
    $fbuser->setId(USER_ID);

    $facebookAdAccounts = $fbuser->getAdAccounts(['id', 'account_id', 'name', 'timezone_name', 'currency']);


Answered By - jackthedev
  • 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