Posts tagged with laravel

The goal is to get data from my submissions table in the database as shown in my code below and upload it to google ads customer match list automatically without having to upload csv files manually with this data. Currently when I ran the command to do upload the data automatically I get this error :

{ "message": "<!DOCTYPE html>\n<html lang=en>\n  <meta charset=utf-8>\n  <meta name=viewport content=\"initial-scale=1, minimum-scale=1, width=device-width\">\n  <title>Error 404 (Not Found)!!1<\/title>\n  <style>\n    *{margin:0;padding:0}html,code{font:15px\/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(\/\/www.google.com\/images\/errors\/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(\/\/www.google.com\/images\/branding\/googlelogo\/1x\/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(\/\/www.google.com\/images\/branding\/googlelogo\/2x\/googlelogo_color_150x54dp.png) no-repeat 0% 0%\/100% 100%;-moz-border-image:url(\/\/www.google.com\/images\/branding\/googlelogo\/2x\/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(\/\/www.google.com\/images\/branding\/googlelogo\/2x\/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}\n  <\/style>\n  <a href=\/\/www.google.com\/><span id=logo aria-label=Google><\/span><\/a>\n  <p><b>404.<\/b> <ins>That\u2019s an error.<\/ins>\n  <p>The requested URL <code>\/v14\/customers\/{$customerID}\/offlineUserDataJobs:create<\/code> was not found on this server.  <ins>That\u2019s all we know.<\/ins>\n", "code": 5, "status": "NOT_FOUND", "details": [] } 

My current code in my command, since I want it to run in the background every night looks like:

<?php namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; use Carbon\Carbon; use Google\Auth\OAuth2; use Google\Ads\GoogleAds\Lib\V14\GoogleAdsClientBuilder; use Google\Ads\GoogleAds\Util\V14\ResourceNames; use Google\Ads\GoogleAds\V14\Services\UserDataOperation; use Google\Ads\GoogleAds\V14\Enums\OfflineUserDataJobTypeEnum\OfflineUserDataJobType; use Google\Ads\GoogleAds\V14\Common\UserIdentifier; use Google\Ads\GoogleAds\V14\Common\OfflineUserAddressInfo; use Google\Ads\GoogleAds\V14\Common\UserData; use Google\Ads\GoogleAds\V14\Services\OfflineUserDataJobOperation; class BulkUploadGoogleAds extends Command{     protected $signature = 'googleads:bulk-upload';     protected $description = 'Fetch today\'s leads, create CSVs, and upload to Google Ads Customer Match lists';     public function handle(){         $this->info('Fetching today\'s leads and preparing CSVs...');         // Fetch today's leads from submissions table         $leads = DB::table('submissions')             ->select(                 DB::raw("JSON_UNQUOTE(JSON_EXTRACT(applicant_info, '$.email')) as email"),                 DB::raw("JSON_UNQUOTE(JSON_EXTRACT(applicant_info, '$.phone')) as phone"),                 DB::raw("JSON_UNQUOTE(JSON_EXTRACT(applicant_info, '$.first_name')) as first_name"),                 DB::raw("JSON_UNQUOTE(JSON_EXTRACT(applicant_info, '$.last_name')) as last_name"),                 DB::raw("'US' as country"),                 DB::raw("JSON_UNQUOTE(JSON_EXTRACT(applicant_info, '$.zip_code')) as zip"),                 DB::raw("JSON_UNQUOTE(JSON_EXTRACT(form_fields, '$.experience')) as experience")             )             ->where('is_qualified', 1)             ->whereDate('created_at', Carbon::today())             ->get();         if ($leads->isEmpty()) {             $this->info('No leads found for today.');             return;         }         // Customer Match list IDs for driving experience         $experienceLists = [             '0'  => '8667734072',             '3'  => '8667763201',             '6'  => '8667739115',             '12' => '8667741140',             '24' => '8668576641',         ];         // Generate and upload CSVs for each list         foreach ($experienceLists as $experience => $listId) {             // Filter leads by experience level             $filteredLeads = $leads->filter(fn($lead) => $this->matchesExperience($lead->experience, $experience));             if ($filteredLeads->isEmpty()) {                 $this->info("No leads for experience level {$experience}. Skipping...");                 continue;             }             // Upload directly to Google Ads             $this->uploadToGoogleAds($filteredLeads, $listId);         }         $this->info('Bulk upload to Google Ads completed successfully.');     }     private function matchesExperience($userExp, $criteria){         $userExp = (int)$userExp;         switch ($criteria) {             case '0': return $userExp == 0;             case '3': return $userExp >= 3 && $userExp < 6;             case '6': return $userExp >= 6 && $userExp < 12;             case '12': return $userExp >= 12 && $userExp < 24;             case '24': return $userExp >= 24;             default: return false;         }     }     private function uploadToGoogleAds($leads, $listId){         $this->info("Uploading data to Google Ads list ID: {$listId}");         $iniConfig = parse_ini_file(base_path('config/google_ads.ini'), true)['GOOGLE_ADS'];         // Build the OAuth2 credentials and Google Ads client         $oauth2 = new \Google\Auth\Credentials\UserRefreshCredentials(             'https://www.googleapis.com/auth/adwords',             [                 'client_id' => $iniConfig['clientId'],                 'client_secret' => $iniConfig['clientSecret'],                 'refresh_token' => $iniConfig['refreshToken'],             ]         );         $googleAdsClient = (new GoogleAdsClientBuilder())             ->withDeveloperToken($iniConfig['developerToken'])             ->withOAuth2Credential($oauth2)             ->withLoginCustomerId($iniConfig['loginCustomerId'])             ->build();         $offlineUserDataJobService = $googleAdsClient->getOfflineUserDataJobServiceClient();         $userDataList = [];         foreach ($leads as $lead) {             $userIdentifiers = [];             if (!empty($lead->email)) {                 $userIdentifiers[] = new UserIdentifier([                     'hashed_email' => $this->normalizeAndHash($lead->email)                 ]);             }             if (!empty($lead->phone)) {                 $userIdentifiers[] = new UserIdentifier([                     'hashed_phone_number' => $this->normalizeAndHash($lead->phone)                 ]);             }             if (!empty($lead->first_name) && !empty($lead->last_name) && !empty($lead->country) && !empty($lead->zip)) {                 $userIdentifiers[] = new UserIdentifier([                     'address_info' => new OfflineUserAddressInfo([                         'hashed_first_name' => $this->normalizeAndHash($lead->first_name),                         'hashed_last_name' => $this->normalizeAndHash($lead->last_name),                         'country_code' => $lead->country,                         'postal_code' => $lead->zip,                     ])                 ]);             }             if (!empty($userIdentifiers)) {                 $userDataList[] = new UserData(['user_identifiers' => $userIdentifiers]);             }         }         if (empty($userDataList)) {             $this->info("No valid user data for list ID: {$listId}. Skipping...");             return;         }         $operations = array_map(fn(UserData $userData) => new OfflineUserDataJobOperation(['create' => $userData]), $userDataList);         $offlineUserDataJob = new \Google\Ads\GoogleAds\V14\Resources\OfflineUserDataJob([             'type' => OfflineUserDataJobType::CUSTOMER_MATCH_USER_LIST,             'resource_name' => ResourceNames::forUserList(                 $iniConfig['loginCustomerId'],                 $listId             ),         ]);         $jobResponse = $offlineUserDataJobService->createOfflineUserDataJob(             $iniConfig['loginCustomerId'],             $offlineUserDataJob         );         $jobResourceName = $jobResponse->getResourceName();         $offlineUserDataJobService->addOfflineUserDataJobOperations($jobResourceName, $operations);         $offlineUserDataJobService->runOfflineUserDataJob($jobResourceName);         $this->info("Job successfully submitted for list ID: {$listId}");     }     private function normalizeAndHash($value){         return hash('sha256', strtolower(trim($value)));     } } 

I'm using this package to send messages on WhatsApp Business, but when I try to use it i get this error:

{"error":{"message":"Unsupported post request. Object with ID 'messages' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api","type":"GraphMethodException","code":100,"error_subcode":33,"fbtrace_id":"AZy2DQf7fRL003f1RJcY8Kf"}}

I tried changing the token many times and also switching phone numbers. What can I do?

Here's what i did:

Added this to config/services.php:

 'whatsapp' => [             'from-phone-number-id' => env('WHATSAPP_FROM_PHONE_NUMBER_ID'),             'token' => env('WHATSAPP_TOKEN'),         ], 

Added application token and phone number id inside .env:

WHATSAPP_FROM_PHONE_NUMBER_ID=XXXXXX WHATSAPP_TOKEN=XXXXXX 

And then I created a notification class in Laravel like the instructions said and used the notification facade to send the message.

I just tried using the notify method of the Notifiable Trait like this:

Route::get('/wa', function () {     $user = User::find(4);     $user->notify(new AppuntamentiPazienti());     return view('homepage'); }); 

but i got the same error.

I'm trying to make a Laravel task that will publish a picture each week on my page.

Here's my code:

public function postToFacebook($message, $imageUrl): array|string{         try {             $response = $this->fb->post('/me/feed', [                 'message' => $message,                 'link' => "https://google.fr",             ], env('FACEBOOK_ACCESS_TOKEN'));             return $response->getDecodedBody();         } catch(\Facebook\Exceptions\FacebookResponseException $e) {             return 'Graph returned an error: ' . $e->getMessage();         } catch(\Facebook\Exceptions\FacebookSDKException $e) {             return 'Facebook SDK returned an error: ' . $e->getMessage();         }     } 

I already checked content of $message and env('FACEBOOK_ACCESS_TOKEN'), everything is OK.

But I always get :

Undefined array key 1 

on post() method.

I am using "facebook/graph-sdk" package.

Is it mandatory to have a FB app up and running ? Mine is not published, but it is asking me a bunch of things, like Business verification that is not very relevant, as I do it for myself...

Do you have any idea how should I fix the issue ?

I have and Facebook developer account created around 4 years before. The problem is when i try to fetch page videos, its not returning any result.

Note: i am using laravel-socialite package and the app is not verified yet.

When tried to debug i found out that the auth toke does not contain "pages_read_user_content" this permission.

On my laravel code i have added this permission but still when i am doing authentication its not showing this permission.

public function login(){     return Socialite::driver('facebook')         ->stateless()         ->setScopes(['pages_read_engagement', 'pages_show_list', 'pages_read_user_content'])         ->usingGraphVersion('v20.0')         ->redirect(); } 

Approach i tried :

To test this i created a new facebook developers account and did all the process and boom it worked. I am attaching the screenshot of permission detail with new developer account.

So the issue is its not working with my old account. Can anyone suggest how to fix this.

Thanks.

I'm using a rich text editor to create social media posts' text and I save it in DB as HTML to keep the format, I want to send these texts to Facebook Graph API formatted for example:

// DB <p>✨ <strong>Discover Elegance Redefined</strong>! Explore the brilliance of this meticulously crafted <em>platinum engagement ring</em>, featuring a stunning <strong>pavé diamond band</strong> that perfectly complements its breathtaking <strong>center stone</strong>. 💍 #ForeverBrilliant #EngagementRing #LuxuryJewelry #DiamondLove ✨</p> 

//FB ✨ Discover Elegance Redefined! Explore the brilliance of this meticulously crafted platinum engagement ring, featuring a stunning pavé diamond band that perfectly complements its breathtaking center stone. 💍 #ForeverBrilliant #EngagementRing #LuxuryJewelry #DiamondLove ✨

I tried to use HTMLPurifier Library but still not working