Posts tagged with php

i have integrated google adsense for my client's website, ads are showing in some devices, but in some devices it showing always, particularly ads are not showing always in my client's devices,

is that any mistake i did on my google adsense account to resolve this issue, or it is the nature of google adsense?

but client's want to get ads for all devices and every time it need to show on his website,

i have tried with lots of blogs about this, everything is failed, and i'm finally here, hopefully i get a valuable knowledge here,

this is my first question on stackoverflow, if i made any mistake on it, please don't mind it, i'll correct on my future questions.

Thanks in advance.

Using bellow code I can get the access and refresh token:

private const SCOPE                 = 'https://www.googleapis.com/auth/adwords'; private const AUTHORIZATION_URI     = 'https://accounts.google.com/o/oauth2/v2/auth'; private const OAUTH2_CALLBACK_PATH  = ''; private const REDIRECT_URL          = 'http://localhost:3000/google/google-ads/confirmed'; $code           = $request->input('code'); $scope          = $request->input('scope'); $state          = $request->input('state'); $project_token  = $request->input('project_token'); $project_name   = $request->input('project_name'); $account_name   = $request->input('account_name'); $account_id     = $request->input('account_id'); $clientId       = 'my-client-id--kh3el.apps.googleusercontent.com'; $clientSecret   = 'my-clicent-secret4cCm'; $redirectUrl    = self::REDIRECT_URL; $oauth2 = new OAuth2(     [         'clientId'              => $clientId,         'clientSecret'          => $clientSecret,         'authorizationUri'      => self::AUTHORIZATION_URI,         'redirectUri'           => $redirectUrl . self::OAUTH2_CALLBACK_PATH,         'tokenCredentialUri'    => CredentialsLoader::TOKEN_CREDENTIAL_URI,         'scope'                 => self::SCOPE,         // Create a 'state' token to prevent request forgery. See         // https://developers.google.com/identity/protocols/OpenIDConnect#createxsrftoken         // for details.         'state' => sha1(openssl_random_pseudo_bytes(1024))     ] ); // Set the authorization code and fetch refresh and access tokens. $oauth2->setCode($code); $authToken = $oauth2->fetchAuthToken(); $refreshToken   = isset( $authToken['refresh_token'] ) ? $authToken['refresh_token'] : ''; $accessToken    = $oauth2->getAccessToken(); 

now how can I get the emaill address? Is there any way?

I am Using Whatsapp Media API to get Image send from user to business number using webhooks and I also get the Image ID and URL and Image as well in Postman but when I use that curl request made from Postman it always shows Facebook error:

Sorry, something went wrong. We're working on it and we'll get it fixed as soon as we can.

But its working fine in Postman what am I doing wrong?

<?php $ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.16 (KHTML, like Gecko) \  Chrome/24.0.1304.0 Safari/537.16'; $curl = curl_init(); curl_setopt_array($curl, array(   CURLOPT_URL => 'Image_URL_from_Api',   CURLOPT_USERAGENT => $ua,   CURLOPT_RETURNTRANSFER => true,   CURLOPT_ENCODING => '',   CURLOPT_MAXREDIRS => 10,   CURLOPT_TIMEOUT => 0,   CURLOPT_FOLLOWLOCATION => true,   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,   CURLOPT_CUSTOMREQUEST => 'GET',   CURLOPT_SSL_VERIFYPEER => false,   CURLOPT_HTTPHEADER => array(     'Authorization: Bearer My_Token'   ), )); $response = curl_exec($curl); curl_close($curl); echo $response; 

I am following this package: https://github.com/googleads/google-ads-php. Here they said that I need to run this page:

https://github.com/googleads/google-ads-php/blob/main/examples/Authentication/GenerateUserCredentials.php

to terminal.

and I did it like:

php /locaation of the fie/GenerateUserCredentials.php 

After that I can get a link which is something like that:

https://accounts.google.com/o/oauth2/v2/auth?response_type=code&access_type=offline&client_id=535777736006-d1rp8msevnls2pmihk7b8l23j3vra7duh.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fcallback&state=4e23ce963534701029c1a22d2de7848d034d8b0b0&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords

(Above link is demo purpose)

So, When I click on this link I redirect to my google account and give access to them and after that I redirect back to this following URL:

http://localhost:3000/auth/callback?state=fddbaae6583b15aba552f682fe9f018233388533555f&code=4%2F0AfgeXvs4NV49mrqEBrl81ATRnXhqcu9x9ja8SAbaENSWhmNejGRGkZJE_AcD1aAFWdrlGg&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fadwords

Here you can see I have 2 params which is state and code.

Now my question is how can I get the access token and refresh token using this URL?

I try to make a keyword searches system for our employ and i have google ads developer token But I cannot able to find any CURL or PHP CURL setup guide.

Two reference links Ad API Examples
Method: customers.generateKeywordIdeas

An example from Google's documentation:

curl -f --request POST "https://googleads.googleapis.com/v${API_VERSION}/customers/${CUSTOMER_ID}/campaignBudgets:mutate" \ --header "Content-Type: application/json" \ --header "developer-token: ${DEVELOPER_TOKEN}" \ --header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \ --header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \ --data "{ 'operations': [   {     'create': {       'name': 'My Campaign Budget #${RANDOM}',       'amountMicros': 500000,     }   },   {     'create': {       'name': 'My Campaign Budget #${RANDOM}',       'amountMicros': 500000,     }   } ] }" 

I try this code but got Error

    <?          $ch = curl_init();          curl_setopt($ch, CURLOPT_URL, 'https://googleads.googleapis.com/v11/customers/(MANAGER_CUSTOMER_ID):generateKeywordIdeas');     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);     curl_setopt($ch, CURLOPT_POST, 1);     curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n\n\"keywordSeed\": {\n    \"keywords\": [\n    \"cofee\"\n  ]\n  }\n}");          $headers = array();     $headers[] = 'Content-Type: application/json';     $headers[] = 'Login-Customer-Id: (MANAGER_CUSTOMER_ID)';     $headers[] = 'Developer-Token: DEVELOPER_TOKEN';     $headers[] = 'Authorization: Bearer (OAUTH_ACCESS_TOKEN)';     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);          $result = curl_exec($ch);     if (curl_errno($ch)) {         echo 'Error:' . curl_error($ch);     }     print_r($result);     curl_close($ch); 

I'm not getting any output