I used Go to call the Google AdMob API to create an ad unit, but it prompted me with a 403 error. I was calling the Google AdMob beta API. I could query the ad units correctly, but when creating, it indicated restricted permissions. I confirmed that I had used the correct permission scope. When I looked at the API documentation, it told me that "This method has limited access. If you see a 403 permission denied error, please reach out to your account manager for access.",In fact, the document does not provide the contact information of the relevant account manager.then I haven't found the contact information of the account manager,So, how should I call this creation method?
this is my test code:
var (
clientID = "my-client-id"
clientSecret = "my-client-secret"
redirectURL = "my-redirect-url"
scopes = []string{admob.AdmobReadonlyScope, admob.AdmobReportScope,".monetization"}
)
func main() {
ctx := context.Background()
config := &oauth2.Config{
ClientID: clientID,
ClientSecret: clientSecret,
RedirectURL: redirectURL,
Scopes: scopes,
Endpoint: google.Endpoint,
}
refreshToken := "my-refresh-token"
tokenSource := config.TokenSource(ctx, &oauth2.Token{RefreshToken: refreshToken})
newToken, err := tokenSource.Token()
if err != nil {
fmt.Printf("error:%s", err)
}
token := &oauth2.Token{
AccessToken: newToken.AccessToken,
RefreshToken: refreshToken,
TokenType: "Bearer",
Expiry: time.Now().Add(1 * time.Hour),
}
client := config.Client(ctx, token)
create(client)
}
func create(client *http.Client) {
ctx := context.Background()
admobService, err := admob.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
panic(err)
}
adUnit := &admob.AdUnit{
Name: "pub-4926433235811020/adUnits/aabbccdd",
DisplayName: "test_create_adunit",
AdFormat: "APP_OPEN",
AdUnitId: "aabbccdd",
AppId: "ca-app-pub-2783529062101020~1234567890",
AdTypes: []string{"RICH_MEDIA"},
}
result, err := admobService.Accounts.AdUnits.Create("accounts/my-account", adUnit).Do()
if err != nil {
fmt.Println(err)
}
fmt.Println(result)
}
Then the code execution result prompts: googleapi: Error 403: The caller does not have permission, forbidden.