Some of the aliases you requested do not exist create Audiences - facebook-graph-api

Earlier I had Facebook personal ad account and with the help of https://developers.facebook.com/docs/marketing-api/reference/custom-audience I used to create custom audience. Now I have shifted to business account and trying to call same create custom audience code and it is giving me following error.
Uncaught exception 'FacebookAds\Http\Exception\AuthorizationException' with message '(#803) Some of the aliases you requested do not exist: createAudiences
Do I need to change marketing API to Business Mapping API or there is some error in current Code?
I am using following code
$audience = new CustomAudience(null, $accountId);
$audience->setData(array(
CustomAudienceFields::NAME => $associative_arr['name'],
CustomAudienceFields::PIXEL_ID => $associative_arr['pixelId'],
CustomAudienceFields::DESCRIPTION => $associative_arr['description'],
CustomAudienceFields::RETENTION_DAYS => $associative_arr['retensionDays'],
CustomAudienceFields::SUBTYPE => CustomAudienceSubtypes::WEBSITE,
CustomAudienceFields::RULE => array('url' => array('i_contains' => $associative_arr['websiteUrl'])),
CustomAudienceFields::PREFILL => $associative_arr['prefill']
));
// Create the audience
$audience->create();
Any suggestions?

Assuming $accountId is in the format act_<AD_ACCOUNT_ID>:
$audience = new CustomAudience(null, $accountId);
Seems like you don't have permission to create an audience in this Ad Account, try debugging your access token here: https://developers.facebook.com/tools/debug/accesstoken

Related

AWS Connect : How do I show company name on outbound calls instead of a phone number , or maybe both?

I have been trying to show up the company name instead of a phone number when an outbound call is initiated automatically at certain times using aws connect contact flow. So far, everything is working as it should be except for showing up the name of the company. I have been trying to find a solution or a documentation on how to show the company name instead of a number but so far could not find anything useful. the only hint I got from aws documentation was , I should set the caller id and name by myself, and no further instruction or hints on how to do it. I Tried to change the phone number using outboundcall api's contact attributes but nothing was showing up.
$result = $client->startOutboundVoiceContact([
'Attributes' => array(
'sourcePhoneNumber' => $d->company_name,
'd`enter code here`ate'=> $d->date,
'time' => $d->time,
'clinic' => $d->company_branch_name,
'address' => $d->company_branch_address,
),
'ContactFlowId' => $this->contactFlowId, // REQUIRED
'DestinationPhoneNumber' => $d->phone_number, // REQUIRED
'InstanceId' => $this->instanceId, // REQUIRED
'SourcePhoneNumber' => $this->sourcePhoneNumber,
]);
'''
where $d is my database and i am getting all the information from there
any recommendation or solution would be very much helpful. thank you.
If I recall correctly this feature is only possible in the US.

Can't resend verification code through AWS Cognito API

I have an AWS Cognito User Pool where users are created through Cognito's API using the AdminCreateUser action, which works fine. This sends out a verification e-mail to the user, containing a temporary password. So far so good.
Now a user did not receive this verification e-mail, so I need to send it again, using the ResendConfirmationCode action. I am attempting to do that with the below PHP code.
$userPoolId = '[POOL_ID_HERE]';
$backendAppId = '[APP_ID_HERE]';
$clientSecret = '[SECRET_HERE]';
$username = '[UUID_HERE]';
$secretHash = base64_encode(hash_hmac('sha256', $username . $backendAppId, $clientSecret, true));
$cognitoIdp->resendConfirmationCode([
'ClientId' => $backendAppId,
'SecretHash' => $secretHash,
'Username' => $username,
]);
That gives me the following error:
Aws/CognitoIdentityProvider/Exception/CognitoIdentityProviderException
with message 'Error executing "ResendConfirmationCode" on
"https://cognito-idp.eu-central-1.amazonaws.com"; AWS HTTP error:
Client error: POST https://cognito-idp.eu-central-1.amazonaws.com
resulted in a 400 Bad Request response:
{"__type":"NotAuthorizedException","message":"Can't resend
confirmation code for this user"} NotAuthorizedException (client):
Can't resend confirmation code for this user -
{"__type":"NotAuthorizedException","message":"Can't resend
confirmation code for this user"}'
I am using the credentials of a user which has the following IAM permissions for the user pool:
cognito-idp:AdminDeleteUser
cognito-idp:AdminCreateUser
cognito-idp:AdminAddUserToGroup
cognito-idp:ResendConfirmationCode
If I test the permissions using the IAM Policy Simulator, it gives me the green light, saying that everything is OK. To my knowledge, the cognito-idp:ResendConfirmationCode action should be sufficient, as sending out the verification e-mail works fine when creating the user.
What am I doing wrong here? An alternative approach would be to invoke the AdminCreateUser action again, setting the MessageAction parameter to RESEND. This would force the verification e-mail to be resent for existing users, but I prefer using the ResendConfirmationCode action if I can get it to work.
Any ideas? Thanks!
I understand that you would like your web application end users to receive a confirmation code again if they do not get the confirmation code due to some reason after they sign-up, and I also understand that you are getting the "NotAuthorizedException" when you are trying to run the ResendConfirmationCode API call from your code that uses the PHP SDK.
The ResendConfirmationCode API call[1] can be used after the sign-up API call[2], and it is not a part of the AdminCreateUser Authentication flow, which is why the error is thrown. The AdminCreateUser API call changes the status of the new user to the "Force Change Password State", and neither the ResendConfirmationCode call or the ForgotPassword call can work after AdminCreateUser is used for creating a new user.
If you would like your end-users to get the confirmation code again, you could use the AdminCreateUser API call itself and set the "RESEND" flag in MessageAction in the PHP code. There would be no other way to send the verification message again in this particular use-case, as per my understanding of Amazon Cognito.
An example of the API call in PHP according to the official documentation is as follows[3]:
$result = $client->adminCreateUser([
'DesiredDeliveryMediums' => ['<string>', ...],
'ForceAliasCreation' => true || false,
'MessageAction' => 'RESEND|SUPPRESS',
'TemporaryPassword' => '<string>',
'UserAttributes' => [
[
'Name' => '<string>', // REQUIRED
'Value' => '<string>',
],
// ...
],
'UserPoolId' => '<string>', // REQUIRED
'Username' => '<string>', // REQUIRED
'ValidationData' => [
[
'Name' => '<string>', // REQUIRED
'Value' => '<string>',
],
// ...
],
]);
After using setting 'MessageAction' as 'RESEND', the end-users should be able to receive the verification message again on their end.
References
[1]. https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/resend-confirmation-code.html
[2]. https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/sign-up.html
[3]. https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-cognito-idp-2016-04-18.html#admincreateuser

How to add people to facebook ad account in business manager

I am trying to create ad account by following https://developers.facebook.com/docs/marketing-api/reference/ad-account. With the help of this code I could successfully create ad account but I want to add myself as people as well but not getting any way to do this.
My ad account creation parameters are like
$attachment = array(
'access_token' => $this->accessToken,
'name' => $associative_arr['name'],
'currency' => $associative_arr['currency'],
'timezone_id' => $associative_arr['timezone_id'],
'end_advertiser' => $this->businessAccount,
'media_agency' => 'NONE',
'partner' => 'NONE',
'user_role' => '1001'
);
and endpoint is
https://graph.facebook.com/v2.8/BUSINESS_ID/adaccount
I also tried updating ad account using following
https://developers.facebook.com/docs/marketing-api/aduser/v2.8
but no gain.
I am getting following error.
stdClass Object
(
[error] => stdClass Object
(
[message] => (#10) Application does not have permission for this action
[type] => OAuthException
[code] => 10
[fbtrace_id] => HyAJtY0OOMf
)
)
Can anyone give me suggestions how I can ad people to my ad account using curl or PHP SDK?
Besides getting the ads_management permission, what was your app's Marketing API access level? The default access level supports up to only 5 ad account access. If you've accessed more than that via the API, you won't be able to do that on more accounts unless you apply for higher level of access. You can manage your ad account list in your app dashboard.

How can I get my facebook personal profile posts using getAccessToken()?

What I am actually trying to do is to retrieve my posts/statuses from my personal facebook profile page (this is not a fan page) and display them in my website. Also please note that every user that will visit my website should be able to view my statuses by means it does not have to do with authenticating them or something like that. This is something that needs to be generated server-side.
I am aware that you can retrieve a JSON string from a URL like this https://graph.facebook.com/MY_PROFILE_ID/feed?access_token=ACCESS_TOKEN because I tried it from the facebook developers (Graph API Explorer) page and it is exactly what I need.
The thing is that when I generate the access token from the Graph API Explorer I can select permissions and it generates the token respectively according to permissions chosen, such as user_status, status_update, etc.
Now I want to accomplish this by using PHP-SDK but I have no idea how to generate an access token the same as the one I generate in the Graph API Explorer.
The basic way to do this is by calling getAccessToken() as shown here. The thing is that when I use the token generated from this simple method the JSON string returned will only show me my basic information.
$config = array(
'appId' => 'MY_APP_ID',
'secret' => 'MY_APP_SECRET',
);
$facebook = new Facebook($config);
$ACCESS_TOKEN = $facebook->getAccessToken();
How can I add permissions for instance? Should I assign parameters somewhere? I spent quite a lot of time reading the facebook API documentation and some other forums but I did not find the answer that I need.
Finally if I get the right access token than I would simply retrieve the JSON string and parse it with what I need.
Thanks.
you need for add permissions in your code for login using the fb js sdk add in the scope this like this example:
$("#login").on('click',function(){
FB.login(function(response){
console.log(response);
},{scope: 'email,manage_pages,read_insights'});
});
or in php fb sdk the next form:
<?php
require 'server/fb-php-sdk/facebook.php';
$app_id = 'APP_ID';
$app_secret = 'APP_SECRET';
$app_namespace = 'APP_NAMESPACE';
$app_url = 'https://apps.facebook.com/' . $app_namespace . '/';
$scope = 'email,publish_actions';
// Init the Facebook SDK
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));
// Get the current user
$user = $facebook->getUser();
// If the user has not installed the app, redirect them to the Login Dialog
if (!$user) {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => $scope,
'redirect_uri' => $app_url,
));
print('<script> top.location.href=\'' . $loginUrl . '\'</script>');
}
?>
the most important for add permission is this part :
$scope = 'email,publish_actions';
you can find all about the extended permissions in this link
https://developers.facebook.com/docs/reference/login/extended-permissions

How to use CUSTOM privacy setting for facebook post from an app in php

In PHP with facebook SDK, when I post from my app using /me/feed, if I use 'SELF' for privacy setting, it works fine. When I change it to CUSTOM with a list of ids to restrict to, I get an error for "friends" was not recognized. What does this mean?
// Works
$privacy = array(
'value' => 'SELF',
);
// Doesn't work and says 'Friends was not recognized'
$privacy = array(
'value' => 'CUSTOM',
'allow' => '{<id1>}'
}
I read through many questions on this topic before asking this one.
Also, this documentation from FB is confusing me as to what is and is not possible for an post from an app.
"Note: The privacy parameter only applies for posts to the user's own timeline and is ultimately governed by the privacy ceiling a user has configured for an app. It does not apply to posts made by an app on behalf of a user to another user's timelines or to Pages, events, or groups. In those cases, such posts are viewable by anyone who can see the timeline or content in the group or event."
you need to add a parameter called 'friends' with the value of 'SOME_FRIENDS'.
like this:
$privacy = array(
'value' => 'CUSTOM',
'friends' => 'SOME_FRIENDS',
'allow' => 'id1,id2,id3'
);