Facebook graph api - Cannot create offers - facebook

I am using the facebook graph api to programmatically create offers on a page, of which the user is an admin of.
I am sure the user is an admin of that page, still I am getting an error to check my admin permission levels (Error below). Any idea why? Any help is appreciated.
If it is of any help, I have added the following scope to my requests: {scope: 'manage_pages,publish_pages'}
{
"error": {
"message": "Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_subcode": 1528104,
"is_transient": false,
"error_user_title": "Check Your Admin Permission Level",
"error_user_msg": "Only some admins of your Page are able to create and edit offers. Talk to the person responsible for your Page about your admin permission level.",
"fbtrace_id": "FgBVmH5BTW0"
}
}
A snapshot of my code is as follows:
accessToken = req.session.access_token;
FB.setAccessToken(accessToken);
FB.api("page-name", {fields: "access_token,id"}, function (res) {
var pageId = res.id;
var pageAccessToken = res.access_token;
FB.setAccessToken(pageAccessToken);
FB.api(pageId + "/offers", 'post', {
title: "Test title",
expiration_time: 'some datetime',
message: "Test offer 1"
}, function (res2) {
resp.send(res2);
});

Related

Failed to change azure account password from MS Graph Explorer

I am trying to change my password of Azure account from Microsoft Graph Explorer by using this query:
POST https://graph.microsoft.com/v1.0/me/changePassword
{
"currentPassword": "XXX",
"newPassword": "XXX"
}
I got the below error while executing that query:
{ "error": { "code": "Authorization_RequestDenied", "message": "Access
to change password operation is denied.", "innerError": { "date":
"2022-07-10T05:59:39", "request-id":
"1ecc339e-62f4-4703-9e92-181f894b9790", "client-request-id":
"b353d155-13c2-0809-4d83-efb8ae999742" } }
Do I need permission to change my own password? What's the resolution?
I tried to reproduce the same in my environment and got the same error as below:
POST https://graph.microsoft.com/v1.0/me/changePassword
Body
{
"currentPassword": "XXXX",
"newPassword": "XXXX"
}
Please note that, you need Directory.AccessAsUser.All permission consented like below:
After consenting, I am able to change my password successfully like below:
Reference:
user: changePassword - Microsoft Graph v1.0 | Microsoft Docs

How to include images in page post API

I keep getting this error message when am attaching images to page post
message: '(#10) Application does not have permission for this action'
but when am posting message only, it works fine
FB.api('PAGE_ID/feed', 'post', {
message: 'Message is here',
link: 'https://my_LINK.com',
"child_attachments": [
{
"link": "https://1.jpg",
"image_hash": "hash1",
"name": "Some Name",
"description": "Some description"
},
{
"link": "https://2.jpg",
"image_hash": "hash2",
"name": "Some Name",
"description": "Some description 2"
}]
}, function (res) {
if (!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
});
to add multi images to a post in facebook, it has to be done in 2 steps as per facebook
to upload image, refer to this and to make the post
function post_fb_ad(description, ad_images) {
attached_media = []
for (var adImg of ad_images) {
attached_media.push({ media_fbid: adImg.id })
}
FB.api('page_id/feed', 'post', {
message: description,
attached_media: attached_media,
access_token: EXD_ACCESS_TOKEN
}, function (res) {
if (!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
console.log('post id is ', res)
});
}
In order to publish to a page, you will need to use a page access token that has publish_pages permission which you may be missing.
You can quickly test the request using the Graph API Explorer tool.
You can also use the Access Token Debugger tool to test what permissions your access token has.
Also, note that publish_pages permission is reviewable and needs to be approved before you can use it with the general public. Prior to approval, you can only test it with an app where you are an admin and in a page where you have admin role.

You don't have required permission to access this profile using facebook api

While I creating ad by facebook graph api I got an error like below
{"error_user_msg": "You don't have required permission to access this profile", "code": 10, "type": "OAuthException", "message": "Application does not have permission for this action", "fbtrace_id": "BTycRY47T1m", "error_user_title": "No permission to access this profile", "error_subcode": 1341012, "is_transient": false}, {"error_user_msg": "You don't have required permission to access this profile", "code": 10, "type": "OAuthException", "message": "Application does not have permission for this action", "fbtrace_id": "ElyXM7OX//O", "error_user_title": "No permission to access this profile", "error_subcode": 1341012, "is_transient": false}]
the page is promoted, and user's task is ['ADVERTISE', 'ANALYZE'] but it always fail to create an ad?
Can you tell me the reason of this error? great thanks..
update:
part of main codes:
...
elif params.objective=="PRODUCT_CATALOG_SALES":
# https://developers.facebook.com/docs/marketing-api/dynamic-product-ads/ads-management/?translation#adtemplate
cre["object_story_spec"]={
"page_id":params.page_id,
"template_data":{
"call_to_action":{
"type":c["type"]
},
"name":c["link_text"],
"description":c["description"],
"link":c["link"],
"message":c["message"]
}
}
cre["product_set_id"]=params.product_set_id
ad={
"name":"Ad_{}_{}".format(params.name,i+1),
"creative":json.dumps(cre),
"status":"PAUSED"
}
ads.append(ad)
...
# then use batch request, and user token to create some ads at one time.
Using user token to create ad in a batch way

I am using ngOpenFB on an ionic app, but I dont manage to get user's email

Login seems to go ok, with the email permission,
however when doing:
var deferred = $q.defer();
$openFB.api({
path: '/me/email'
}).then(function( res ) {
deferred.resolve(res);
//angular.extend(me, {picture: res.data.url});
}).catch(function(err){
console.log(err);
deferred.reject(err);
});
I get an error wrong path.
Ben
/me/email is not a valid endpoint. This is how you get the email of a user: /me?fields=email
The error (from the API Explorer):
{
"error": {
"message": "Unknown path components: /email",
"type": "OAuthException",
"code": 2500,
"fbtrace_id": "FBdZx0Yntxz"
}
}

Cannot delete Facebook some test users

When I call:
$ curl 'https://graph.facebook.com/v2.2/<APP_ID>/accounts/test-users?access_token=<APP_ACCESS_TOKEN>&limit=500'
I see 82 accounts, and all but one look like this:
{
"id": "1413484435585065",
"login_url": "https://developers.facebook.com/checkpoint/test-user-login/1413484435585065/"
}
That is, they have no access token.
When I try to delete them I get:
$ curl -XDELETE 'https://graph.facebook.com/v2.2/1413484435585065?access_token=<APP_ACCESS_TOKEN>'
{
"error": {
"message": "(#100) Invalid value specified for param: id",
"type": "OAuthException",
"code": 100
}
}
The only one that DOES have an access token returns:
{
"error": {
"message": "(#2904) You cannot delete the Open Graph Test User for your app.",
"type": "OAuthException",
"code": 2904
}
}
If I go to Roles...Test Users on the Developers page of the app, then it is empty!
Any new test users I create I can see on the Developers page, and I can delete them using the mentioned curl call.
Where could these test users come from, and how do I get rid of them? Or at least filter them when I am listing test users.