Posts tagged with php

I have a Basic Access Token for my manager account 1234567890 I also have one account under this manager account: 0987654321

I've then followed the documentation, installed libraries, generate OATH2, refresh token etc and filled the "google_ads_php.ini" fileand then:

I'm trying to run the example code in the google documentation:

    $oAuth2Credential = (new OAuth2TokenBuilder())         ->fromFile('/google_ads_php.ini')         ->build();     $googleAdsClient = (new GoogleAdsClientBuilder())         ->fromFile('/google_ads_php.ini')         ->withOAuth2Credential($oAuth2Credential)         ->build();           $googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();     $query = 'SELECT campaign.id, campaign.name FROM campaign ORDER BY campaign.id';     $stream = $googleAdsServiceClient->searchStream($customerId, $query); 

In my google_ads_php.ini, I have this: loginCustomerId = "1234567890"

In the $customerId filed, I have this: "0987654321"

And I'm receiving this error: USER_PERMISSION_DENIED

Also just because I've started becoming crazy I did try all 4 possible combinations:

loginCustomerId = "1234567890" $customerId = "1234567890"

loginCustomerId = "0987654321" $customerId = "0987654321"

loginCustomerId = "0987654321" $customerId = "1234567890"

But I'm receiving this error in all the cases. Any help would be much appreciated

I am having trouble to add a reaction to a message through the whatsapp API. I am receiving an good response like the one in the docs

I am posting to https://graph.facebook.com/v18.0/{fromNumber}/messages with the following data:

{   "messaging_product": "whatsapp",   "to": {toNumber},   "type": "reaction",   "reaction": {     "message_id": {messageID",     "emoji": "💭"   } }

And receiving a good response:

{   "messaging_product": "whatsapp",   "contacts": [     {       "input": {toNumber},       "wa_id": {toNumber}     }   ],   "messages": [     {       "id": {responseWaId}     }   ] } 

But sadly no reaction to the message is given

I am using PHP:

/**  * Markeer bericht met reactie  *  * @param string $toNumber  * @param string $message  * @return int  */ public function markMessageWithEmoji(string $messageId){     $url = "https://graph.facebook.com/v18.0/{$this->fromNumber}/messages";     $response = Http::withHeaders([         'Authorization' => 'Bearer ' . $this->whatsappToken,         'Content-Type' => 'application/json',     ])->post($url, [         'messaging_product' => 'whatsapp',         'recipient_type' => 'individual',         'to' => $this->toNumber,         'type' => 'reaction',         'reaction' => [             'message_id' => $messageId,             'emoji' => '💭',         ],     ]);     return $response->status(); } 

I am sure the message id is correct, since I use the same ID to set the received message as read and this works as expected

I am building a website in which i want that when a user places an order, store owner should receive the order details in his whatsapp. Like First and last name, address, email, mobile and products which he purchased. Currently i tried Twilio for this purpose, but i don't want to use any 3rd party for this. I want to use only CORE PHP and whatsapp business api or library to achieve this.

Here is what i have done so far.

`<?php require 'vendor/autoload.php'; use Twilio\Rest\Client; $accountSid = '0000-0000-0000-0000-00000'; $authToken  = '0000-0000-00000-00000-00000'; $twilioNumber = 'whatsapp:+12000000000';  $whatsappNumber = 'whatsapp:+1255844885454';  $firstName = $_POST['first_name']; $lastName = $_POST['last_name']; $address = $_POST['address']; $townCity = $_POST['town_city']; $mobile = $_POST['mobile']; $totalprice = $_POST['totalprice']; $orderDetails = "First Name: $firstName\nLast Name: $lastName\nAddress: $address\nTown/City: $townCity\nMobile: $mobile\nTotal Amount: Rs$totalprice"; $client = new Client($accountSid, $authToken); try {     $message = $client->messages->create(         $whatsappNumber,         array(             'from' => $twilioNumber,             'body' => $orderDetails         )     );     header("Location: checkout.php");     exit(); } catch (Exception $e) {     echo 'Error: ' . $e->getMessage(); } ` 

I am trying to replicate the Google Ads API Laravel Sample app and port it to a Laravel Jetstream application.

I keep getting the following error: Target class [GoogleAdsApiController] does not exist.

GoogleAdsApiController

<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Google\Ads\GoogleAds\Lib\V15\GoogleAdsClient; use Google\Ads\GoogleAds\Util\FieldMasks; use Google\Ads\GoogleAds\Util\V15\ResourceNames; use Google\Ads\GoogleAds\V15\Enums\CampaignStatusEnum\CampaignStatus; use Google\Ads\GoogleAds\V15\Resources\Campaign; use Google\Ads\GoogleAds\V15\Services\CampaignOperation; use Google\Ads\GoogleAds\V15\Services\GoogleAdsRow; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\View\View; class GoogleAdsApiController extends Controller{     private const REPORT_TYPE_TO_DEFAULT_SELECTED_FIELDS = [         'campaign' => ['campaign.id', 'campaign.name', 'campaign.status'],         'customer' => ['customer.id']     ];     private const RESULTS_LIMIT = 100;  ... 

Routes/Web.php

<?php use Illuminate\Support\Facades\Route; use App\Http\Controllers\GoogleAdsApiController; Route::middleware([     'auth:sanctum',     config('jetstream.auth_session'),     'verified', ])->group(function () {     Route::get('/dashboard', function () {         return view('dashboard');     })->name('dashboard'); }); Route::post(     'pause-campaign',     'GoogleAdsApiController@pauseCampaignAction' ); Route::match(     ['get', 'post'],     'show-report',     'GoogleAdsApiController@showReportAction' );  Route::get('/', function () {     return view('welcome'); }); Route::get('/main', function () {     return view('main'); }); 

Any help is much appreciated

I'm trying to use the API to send to myself a custom message, I can already send a hello world template, but I been unable to send myself a custom only text message.

//API token given by Meta         $token = '*private*';         //Reciever number of msg         $telefono = '*private*';         //URL of msg given by Meta         $url = '*I think is private too*';         $mensaje = '{"messaging_product": "whatsapp", "to": "'.$telefono.'", "type": "text", "text": {"preview_url": false, "body": "MESSAGE_CONTENT" }}'; //header of msg $header = array("Authorization: Bearer " . $token, "Content-Type: application/json"); 

so that's what I use to make the Curl to send the message, which I do like this

//curl init         $curl = curl_init();         curl_setopt($curl, CURLOPT_URL, $url);         curl_setopt($curl, CURLOPT_POSTFIELDS, $mensaje);         curl_setopt($curl, CURLOPT_HTTPHEADER, $header);         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);         //get response from information sent         $response = json_decode(curl_exec($curl),true);         //print response         print_r($response);         //get curl response code         $status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);         print_r($status_code);         //close curl         curl_close($curl); 

I think is kind of working, because it shows on screen this result

Array ( [messaging_product] => whatsapp [contacts] => Array ( [0] => Array ( [input] => phone [wa_id] => 56994134989 ) ) [messages] => Array ( [0] => Array ( [id] => i think is private too ) ) ) 200

In the end I just need to test if its possible to send myself custom text messages, the thing is that this code isn't working as I want it to, as you should see, on the print of the result and the status_code, the code is 200 what makes me think that the request is going through at some point but maybe it need something else to finally be sent to my phone.