Posts under category Meta & Facebook

  • I'm using Laravel Socialite to handle Facebook authentication in my Laravel application, and I’m working in a test environment only. I have successfully integrated Socialite to allow users to log in with their Facebook accounts. Now, I need to fetch a list of the user's Facebook friends after they authenticate.

  • I've reviewed the Laravel Socialite documentation and the Facebook Graph API documentation, but I’m unsure how to proceed with obtaining the list of friends.

  • Facebook Permissions: I’ve made sure to request the user_friends permission during the login process.

  • API Calls: I’ve attempted to use the Graph API directly to fetch friends but haven't been able to integrate it smoothly with Socialite.

Here’s a snippet of the code I’m using to authenticate users:

public function redirectToProviderFacebook(){        return Socialite::driver('facebook')->scopes(['user_friends'])->redirect();     } public function handleProviderCallbackFacebook(Request $request){         try {             $user = Socialite::driver('facebook')->stateless()->user();             $accessToken = $user->token;             // Get friends             $response = Http::withToken($accessToken)                 ->get('https://graph.facebook.com/me/friends');             $friends = $response->json();             dd($friends);             $data = User::where`your text`('email', $user->email)->first();             if (is_null($data)) {                 $users['name'] = $user->name;                 $users['email'] = $user->email;                 $users['password'] = Hash::make('password');                 $data = User::create($users);             }             Auth::login($data);             return redirect('dashboard');         } catch (\Exception $e) {             // Log the error or return a meaningful message             Log::error('Facebook OAuth error: ' . $e->getMessage());             return redirect()->route('login')->with('error', 'Authentication failed.');         }     } 
  • How do I use Laravel Socialite to fetch a user’s list of friends from Facebook in a test environment?

  • Are there any specific settings or configurations needed in the Facebook Developer Console for accessing friends data in a test environment?

  • Can you provide an example of how to make a request to the Facebook Graph API to get friends data after authentication?

Any guidance or examples would be greatly appreciated!

Since today the following request
curl 'https://graph.facebook.com/v17.0/1799561253793262/products?access_token=$ACCESS_TOKEN&summary=&fields=id%2Cname%2Cprice%2Cretailer_id&filter=%7B%22retailer_id%22%3A%20%7B%22contains%22%3A%20%2243214b42-30fe-4306-bf44-10a46e68f105%22%7D%7D&limit=100' | jq '.data[]'
with same url decoded, for your reference and readability:
https://graph.facebook.com/v17.0/1799561253793262/products?access_token=$ACCESS_TOKEN&summary=&fields=id,name,price,retailer_id&filter={"retailer_id": {"contains": "43214b42-30fe-4306-bf44-10a46e68f105"}}&limit=100
does not return all requested product fields as per the request query parameters:
&fields=id,name,price,retailer_id
Instead the request only returns products with the field name:
{"data": [{"name": "Museau 400 g"}], ...}
Expected:
{"data": [{"id": "..........", "name": "Museau 400 g", "price": ....., "retailer_id": .......}], ...}
All graphi api versions are affected.
I kindly ask for your support.

I’m facing an issue where the Facebook Graph API is not returning lead data for a specific ad, even though the leads are visible in the Ads Manager.

Here’s what I’ve done: I’m using the following endpoint to retrieve the leads: GET /{ad_id}/leads?fields=id,created_time,field_data&limit=1000

The leads for other ads are returned correctly, but for one particular ad ("ad1 - Copy"), no leads are returned, even though I can clearly see them in the Facebook Ads Manager (65 leads in total). I’ve made sure that my access token has the required permissions: leads_retrieval ads_read ads_management pages_manage_ads I’ve also tried adding parameters like date_preset=maximum, but this doesn't help with retrieving the missing leads. I've checked Stack Overflow and the Facebook Developer forums, but I haven't found a solution specific to this issue. Has anyone encountered a similar issue, and is there a known fix or workaround for this discrepancy between the Ads Manager and the API? Any help or guidance would be greatly appreciated!

Environment: API version: v20.0 Access token permissions: leads_retrieval, ads_read, ads_management What I’ve Tried: Refreshing the token and regenerating it with proper permissions. Adding various query parameters (like limit and date_preset). Expected Behavior: The API should return all leads for "ad1 - Copy" just like it does for other ads.

I Am trying to upload Reels from a business Instagram account for that i already have access token and long lived token.The problem is that whenever i try to publish a reel it gives me "The video file you selected is in a format that we don't support." error code:352 and error_subcode:2207026.I have also converted that video but its saying the same.But I am able to upload a video of "640x480" but not any other resolution like 720x1280 etc. The url of video is aws

I have tried converting video using ffmpeg but it gives me aspect ratio error on 720x1280 whether its 9:16 or 16:9 when i try to upload video of like 1080x1920 it gives me streams error i have also added validation in my uploadReel function and funtion return true but still i am getting video format not supported error

import { Request, Response } from 'express'; import axios from 'axios'; import asyncHandler from '../../../middlewares/asyncHandler'; import ffmpeg from 'fluent-ffmpeg'; import ffmpegInstaller from '@ffmpeg-installer/ffmpeg'; ffmpeg.setFfmpegPath(ffmpegInstaller.path); export const uploadReel = asyncHandler(async (req: Request, res: Response) => {   const { longLivedToken, videoUrl }: any = req.body;   if (!longLivedToken || !videoUrl) {     return res.status(400).json({ error: 'Invalid data' });   }   console.log('Checking video format for:', videoUrl);   // Check if the video has supported codecs (H.264 for video and AAC for audio)   ffmpeg(videoUrl).ffprobe((err, metadata) => {     if (err) {       console.error('Error reading video metadata:', err.message);       return res.status(400).json({ error: 'Unable to check video metadata or invalid file.' });     }     console.log('Video metadata:', JSON.stringify(metadata, null, 2));     const hasValidCodec = metadata.streams.some(       (stream: any) => stream.codec_name === 'h264' && stream.codec_type === 'video'     ) && metadata.streams.some(       (stream: any) => stream.codec_name === 'aac' && stream.codec_type === 'audio'     );     if (!hasValidCodec) {       console.error('Unsupported file format. Expected H.264 video codec and AAC audio codec.');       return res.status(400).json({         error: 'Unsupported file format. Ensure the video is in MP4 format with H.264 video codec and AAC audio codec.',       });     }     console.log('Video format is supported. Proceeding with upload.');     // If format is supported, proceed to upload the video     axios.post(       `https://graph.instagram.com/v20.0/me/media`,       {         media_type: 'REELS',         video_url: videoUrl, // Publicly accessible URL of the video file         access_token: longLivedToken,       },       {         headers: { 'Content-Type': 'application/json' },       }     )       .then((response) => {         console.log('Reel successfully uploaded:', response.data);         return res.status(200).json({ mediaId: response.data.id });       })       .catch((error) => {         console.error('Error uploading reel:', error.response ? error.response.data : error.message);         return res.status(500).json({ error: 'Failed to upload reel' });       });   }); }); export const publishReel = asyncHandler(async (req: Request, res: Response) => {   const { mediaId, longLivedToken }: any = req.body;   if (!mediaId || !longLivedToken) {     return res.status(400).json({ error: 'Invalid data' });   }   try {     const response = await axios.post(       `https://graph.instagram.com/v20.0/me/media_publish`,       {         creation_id: mediaId,         access_token: longLivedToken,       },       {         headers: { 'Content-Type': 'application/json' }       }     );     return res.status(200).json({ postId: response.data.id }); // Return post ID   } catch (error) {     console.error('Error publishing image:', error.response ? error.response.data : error.message)}      }); 

enter image description here`