Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook - You don't have required permission to access this profile

I'm trying to build a service that let's users create facebook ads with a custom audience based on our database of emails.

Before creating the facebook ad I want to create a preview of the ad. This works just fine when I login in with my own account (admin of facebook app) but fails when logging in as test user.

This is what the user will do: 1. Visit the website of the service. 2. Login using Facebook account with scope: public_profile,email,manage_pages,publish_pages,business_management,ads_management 3. Select facebook page to use 4. Create AdCreative. From this an ad preview can be made. But it fails creating an Adcreative and gives me the following error:

"error":{"message":"Application does not have permission for this action","type":"OAuthException","code":10,"error_subcode":1341012,"is_transient":false,"error_user_title":"No permission to access this profile","error_user_msg":"You don't have required permission to access this profile","fbtrace_id":"EgTeMOXPCUp"}}

The access token as well as ad account belongs to the facebook app. I tried to use the page access token as well but then I don't have permission to access the ad account. This is code:

function fbadcreative($url, $message, $carasoul, $fbtoken, $pageid){

$calength = count($carasoul);
$children = array();
for($i = 0; $i < $calength; $i++){
    $caitem = $carasoul[$i];
    $caitem['hash'] = fbaddimage($caitem['picture'], $caitem['id']);
    $child = (new AdCreativeLinkDataChildAttachment())->setData(array(
        AdCreativeLinkDataChildAttachmentFields::LINK => $caitem['link'],
        AdCreativeLinkDataChildAttachmentFields::NAME => $caitem['name'],
        AdCreativeLinkDataChildAttachmentFields::DESCRIPTION => $caitem['description'],
        AdCreativeLinkDataChildAttachmentFields::IMAGE_HASH => $caitem['hash'],
    ));
    $children[] = $child;
}
$link_data = new AdCreativeLinkData();
$link_data->setData(array(
  AdCreativeLinkDataFields::LINK => $url,
  AdCreativeLinkDataFields::CAPTION => $url,
  AdCreativeLinkDataFields::MESSAGE => $message,
  AdCreativeLinkDataFields::MULTI_SHARE_END_CARD => false,
  AdCreativeLinkDataFields::MULTI_SHARE_OPTIMIZED => false,
  AdCreativeLinkDataFields::CHILD_ATTACHMENTS => $children,
));
$object_story_spec = new AdCreativeObjectStorySpec();
$object_story_spec->setData(array(
  AdCreativeObjectStorySpecFields::PAGE_ID => $pageid,
  AdCreativeObjectStorySpecFields::LINK_DATA => $link_data,
));

$creative = new AdCreative(null, 'act_<accountid>');
$creative->setData(array(
  AdCreativeFields::NAME => $url,
  AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
try {
    $creative->create();
     return $creative->id;
    //return $creative->read(array(AdCreativeFields::ID,));
} catch (FacebookAds\Http\Exception\AuthorizationException $e) {
    echo 'Message: ' . var_dump($e);
    $previousException = $e->getPrevious();
    // Do some further processing on $previousException
    exit;
}
like image 394
user1411626 Avatar asked Apr 05 '17 14:04

user1411626


People also ask

How do I enable permissions on Facebook?

Adjust PermissionsClick “Edit Settings” next to Apps You Use on the Apps, Games and Websites page settings page. Click the app for which you want to adjust the settings. All of the permissions granted to the app will be displayed. Click “Remove” to delete any of the permissions.

Why is Facebook saying I have insufficient permissions?

However, when you do that, you remove the necessary steps that allow us to send your post through or to connect other pages you might need later on. When this happens, you will get the "Insufficient Permission" error when trying to post or you won't be able to see certain Facebook Pages you manage in your list.

Why can't I open someone's profile on Facebook?

If a user has blocked you, or if you have blocked them, you will not be able to see their profile. If one of you has blocked the other, you will not see their name appear as a hyperlink, but in the event you still attempt to view their profile you may see the "Profile Unavailable" error.


2 Answers

I know this is an older post, but it might be interesting for others to read how to solve this.

You need to give the user that requests via api the Advertise and analyze permissions on the PAGE the ad creative will be created for.

Example request here using the graph explorer: page_id/assigned_users?user=system_user_id&tasks=['ADVERTISE', 'ANALYZE']

like image 142
Stormnorm Avatar answered Sep 21 '22 23:09

Stormnorm


In my case i am getting this same error due to giving the wrong page Id , i was giving the another page id that was not linked to this ad account.

like image 25
Hammad ul Hasan Avatar answered Sep 19 '22 23:09

Hammad ul Hasan