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.
Related
Summary:
I tried to obtain AWS Cognito User name (OAuth2 from Google) with Perl module Paws::CognitoIdp::GetUser but I failed the code:
my $GetUserResponse = $cognito_idp->GetUser(
AccessToken => 'MyTokenModelType',
);
with the error Invalid Access Token.
Environment
I am developing Web service with following environment:
AWS + EC2 + Ubuntu 20.04 + nginx 1.20.1 + Perl 5.30.0
Using Cognito with Google OAuth2.0
What I can do now
When you access my Web service, Sign In with Google button will appear. If you click it, you can run my Perl CGI script.
What I cannot do now
I want to obtain your Google user name and mail address, but I cannot.
What I did
I wrote the following code:
my $cognito_idp = Paws->service('CognitoIdp',
region => "ap-northeast-1",
max_attempts => 3,
);
my $GetUserResponse = $cognito_idp->GetUser(
AccessToken => 'MyTokenModelType',
);
my $uname = $GetUserResponse->Username;
Then...
When I access my Web service, it failed with the Software error:
Software error:
Invalid Access Token
Trace begun at /usr/local/share/perl/5.30.0/Paws/Net/JsonResponse.pm line 22
Paws::Net::JsonResponse::process('Paws::Net::JsonResponse=HASH(0x56495fb33d78)', 'Paws::CognitoIdp::GetUser=HASH(0x56495fb41fd0)', 'Paws::Net::APIResponse=HASH(0x56495fde6f38)') called at /usr/local/share/perl/5.30.0/Paws/Net/Caller.pm line 46
Paws::Net::Caller::caller_to_response('Paws::Net::Caller=HASH(0x56495da09a38)', 'Paws::CognitoIdp=HASH(0x56495e05da48)', 'Paws::CognitoIdp::GetUser=HASH(0x56495fb41fd0)', 'Paws::Net::APIResponse=HASH(0x56495fde6f38)') called at /usr/local/share/perl/5.30.0/Paws/Net/RetryCallerRole.pm line 19
Paws::Net::RetryCallerRole::do_call('Paws::Net::Caller=HASH(0x56495da09a38)', 'Paws::CognitoIdp=HASH(0x56495e05da48)', 'Paws::CognitoIdp::GetUser=HASH(0x56495fb41fd0)') called at /usr/local/share/perl/5.30.0/Paws/CognitoIdp.pm line 331
Paws::CognitoIdp::GetUser('Paws::CognitoIdp=HASH(0x56495e05da48)', 'AccessToken', 'MyTokenModelType') called at /DocumentRoot/index.cgi line 16
For help, please send mail to this site's webmaster, giving this error message and the time and date of the error.
Maybe...
I referred following to the documentation
Maybe 'MyTokenModelType' is just the placeholder and I should specify the correct code.
But I don't know how I can make it.
In addition, I want to know how can I obtain not only user name but also user email address.
(Additional Info 2021-11-12)
Thanks to the comment, I read the article:
How to generate access token for an AWS Cognito user?
and I hacked AWS CLI command but I have not got the answer yet.
I think I got to do $ aws connito-idp initiate-auth but I cannot find what arguments I should pass.
In the AWS => Cognito => Users and groups menu, I see the entry of a user of my Web app.
Username: google_??????????
Enabled: Enabled
Account status: EXTERNAL_PROVIDER
Email: (users_email)
I changed my code like this for the experiment to find what information my Web app has.
use Data::Dumper;
my $cognito_idp = Paws->service('CognitoIdp',
region => "ap-northeast-1",
max_attempts => 3,
);
# my $GetUserResponse = $cognito_idp->GetUser(
# AccessToken => 'MyTokenModelType',
# );
# my $uname = $GetUserResponse->Username;
print "Content-type: text/html\n\n\n";
print '<!DOCTYPE html>';
print '<html><pre>';
print Dumper $cognito_idp;
print '</pre></html>';
and I see the contents of $cognito_idp like this:
$VAR1 = bless( {
'_region_for_signature' => 'ap-northeast-1',
...
'credentials' => bless( {
...
'selected_provider' => bless( {
'expiration' => 1636712506,
'actual_creds' => {
'Type' => 'AWS-HMAC',
'SecretAccessKey' => '??????????????',
'Code' => 'Success',
'AccessKeyId' => '???????????????',
'LastUpdated' => '2021-11-12T03:54:16Z',
'Token' => '?????????????????????????????????????',
'Expiration' => '2021-11-12T10:21:46Z'
},
...
I hope I could get the information of the user from the data above.
My question is, how I can specify the MyTokenModelType value of the code:
my $GetUserResponse = $cognito_idp->GetUser(
AccessToken => 'MyTokenModelType',
);
Still I want your info.
Thanks again.
Here is my scenario:
Have have a UserPool and an IdentityPool setup via Cognito. I also have an API-Gateway endpoint cofigured to authenticate with AWS_AIM.
First I log a user into the Cognito UserPool using their username and password. The response I receive is positive and looks like the following:
[AuthenticationResult] => Array
(
[AccessToken] => <AccessToken>
[ExpiresIn] => 3600
[TokenType] => Bearer
[RefreshToken] => <RefreshToken>
[IdToken] => <IdToken>
)
Using this information, I authorise the user with the Cognito IdentityPool. The response I receive is positive and looks like the following:
[IdentityId] => <IdentityId>
[Credentials] => Array
(
[AccessKeyId] => <AccessKeyId>
[SecretKey] => <SecretKey>
[SessionToken] => <SessionToken>
[Expiration] => Aws\Api\DateTimeResult Object
(
[date] => 2018-06-15 09:11:32.000000
[timezone_type] => 1
[timezone] => +00:00
)
)
And this is where I am stuck. I need the following headers in order to make the actual request to the API-Gateway Endpoint:
Authorization: AWS4-HMAC-SHA256
Credential=AKIAIOSFODNN7EXAMPLE/20130524/us-east-1/s3/aws4_request,
SignedHeaders=host;range;x-amz-date,
Signature=fe5f80f77d5fa3beca038a248ff027d0445342fe2855ddc963176630326f1024
But for the life of me I can't find a way to generate these headers. And the AWS SDK Documentation sets for Javascript and PHP is not particularly clear on what exactly to do. So my geuss is I missed a bit somewhere. Does any one have any knowledge on how to correctly generate these headers? Preferably using PHP.
I'm not well with PHP, but I know you need SignatureV4 signed request...isn't this what you are looking for?
https://github.com/aws/aws-sdk-php/blob/master/src/Signature/SignatureV4.php#L42
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
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
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'
);