Posts tagged with facebook-graph-api

So,I managed to get an API key with the correct permissions to make posts as a Page. Based off of some online reading, other users should not see the posts I make just yet as my Facebook App has not yet gone live. However, according to those texts, I should still be able to see them as I am the admin, but I check the page, and I cannot see any post that I've made through the Graph API. I'm not sure if I'm done something wrong or not. No errors appears, no crashes occur.

Edit: Using a different source text, the new posts appear for some reason. I'm wondering if this has to do with links in the content. Do links within these kinds of posts have to appear under their own parametre(s)?

We have a Facebook App created with a dummy User to manage Ads and Audience to which it has access to. Unfortunately it's complicated at the moment to create it under a proper company's User, because we manage many Pages and Clients and there is a lot of burocracy.

In any case, the Access Token associated to this Facebook App works fine and has its live span set to 90 days: the trouble is that after 30 days of the dummy User's inactivity on Facebook, the user get dissociated from the Facebook App. This results in our automated refreshToken call to fail. We have to manually login and re-connect the User to the Application. In fact, the APIs calls we do for our business purpose aren't enough / aren't considered as User's actions: this sound both fair and unintuitive.

Is there a knowkn way or an API call (even as simple as "list your own feed") to keep the User's session active?

Thank you in advance for any tips.

My current project involves creating a social media management app using Nest.js and Next.js. Passport Facebook has been set up on my server side and tested on the server side, and it works well. When I move to the client side and attempt to verify if the access token is saved on the database or not, i sent a request to the endpoint 'api/social-accounts/facebook', but Facebook seems to block it. This is the error message I received. : 'Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.facebook.com/v3.2/dialog/oauth?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2Fapi%2Fsocial-accounts%2Ffacebook%2Fcallback&client_id=1169598374207494. (Reason: CORS request did not succeed). Status code: (null).' here is my controller :

@Controller('api/social-accounts') export class SocialAccountsController {   constructor(private readonly socialAccountService: SocialAccountsService) {}   @UseGuards(AuthGuard('facebook'))   @Get('facebook')   async getAccessToken() {     console.log('arrived here. [get access token]');   }   @Get('facebook/callback')   @UseGuards(AuthGuard('facebook'))   async facebookAuthCallback(@Req() req: any) {     const { socialAccount, user } = req;     const { accessToken, profile } = socialAccount;     await this.socialAccountService.saveSocialAccountAccessToken(       {         access_token: accessToken,         expires_in: null,         social_user_id: profile?.id,       },       user,     );     return 'Your account has been connected.';   } } 

here is my facebook strategy :

import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { PassportStrategy } from '@nestjs/passport'; import { Strategy } from 'passport-facebook'; import { SocialAccountsService } from '../social-accounts.service'; @Injectable() export class FacebookStrategy extends PassportStrategy(Strategy, 'facebook') {   constructor(private readonly config: ConfigService) {     super({       clientID: config.get<string>('APP_ID'),       clientSecret: config.get<string>('APP_SECRET'),       callbackURL:         'http://localhost:8000/api/social-accounts/facebook/callback',       profileFields: ['id'],     });   }   async validate(     accessToken: string,     _refreshToken: string,     profile: any,     done: any,   ): Promise<any> {     const socialAccount = { accessToken, social_user_id: profile.id };     console.log({ socialAccount });     done(null, socialAccount);   } } 

I am try to connect the facebook account without using passport but still has seem issue. Adding a mechanism to authenticate to the app with a Facebook account is not something I want to do. I want the user to be able to add their Facebook account to the app to manage it.

I'm using official Facebbok API for getting ads with /ads_archive endpoint.

Example request:

curl -G \ -d "search_terms='oil'" \ -d "ad_reached_countries=['US']" \ -d "fields=id,ad_creation_time,ad_creative_bodies,ad_creative_link_captions,ad_creative_link_descriptions,ad_creative_link_titles,ad_delivery_start_time,ad_delivery_stop_time,ad_snapshot_url,age_country_gender_reach_breakdown,beneficiary_payers,bylines,currency,delivery_by_region,demographic_distribution,estimated_audience_size,eu_total_reach,impressions,languages,page_id,page_name,publisher_platforms,spend,target_ages,target_gender,target_locations" \ -d "access_token={ACCESS_TOKEN}" \ "https://graph.facebook.com/v19.0/ads_archive" 

Response does include Facebook Page ID. It also includes publisher_platforms field containing Instagram or/and Facebook. But no Instagram ID or username.

I find it weird, because web version of Ad Library (running under private API) shows that data. Example link

How can I get Instagram username using Official Ad Library API?

I've already passed all fields from Archived Ad Schema to my request.

Scraping private API seems hard, because it seems sensitive to proxies.

I am trying to send messages using Graph API where I have certain permissions

email, pages_show_list, business_management, pages_messaging, pages_messaging_subscriptions, instagram_basic, instagram_manage_comments,instagram_manage_insights, instagram_content_publish,, instagram_manage_messages, pages_read_engagement, pages_manage_metadata, pages_read_user_content

Now the wierd part is I have two Roles(Admin both of them, both of them has a Facebook page and connected business instagram account) in the app, Now for one user I am able to send message while in other i get a 403 error

error Data: {   error: {     message: '(#200) Please check if access token has enough IG permissions granular scopes for IG to send API, or if IGSID is valid.',     type: 'OAuthException',     code: 200,     error_subcode: 2534067,     fbtrace_id: 'AouX27HuHoQBu65bb6rBUal'   } } Error Status: 403 Error Headers: AxiosHeaders {   vary: 'Origin',   'access-control-allow-origin': '*',   'cross-origin-resource-policy': 'cross-origin',   'x-app-usage': '{"call_count":5,"total_cputime":0,"total_time":3}',   'content-type': 'application/json',   'www-authenticate': 'OAuth "Facebook Platform" "insufficient_scope" "(#200) Please check if access token has enough IG permissions granular scopes for IG to send API, or if IGSID is valid."',   'facebook-api-version': 'v19.0',   'strict-transport-security': 'max-age=15552000; preload',   pragma: 'no-cache',   'cache-control': 'no-store',   expires: 'Sat, 01 Jan 2000 00:00:00 GMT',   'x-fb-request-id': 'AouX27HuHoQBu65bb6rBUal',   'x-fb-trace-id': 'ERIKbq1Rjf7',   'x-fb-rev': '1012935256',   'x-fb-debug': 'mVMrRrBF3H+nrrHR45BNeWtyqALnup35FrQb9RD8JNQCpmH3n8NhTPYqWVns6Snt1oY6x7RCHIvGzO1cJLP9UQ==',   date: 'Sat, 20 Apr 2024 18:38:20 GMT',   'proxy-status': 'http_request_error;   ......... <some other headers> 'x-fb-connection-quality': 'EXCELLENT; q=0.9, rtt=5, rtx=0, c=10, mss=1380, tbw=372, tp=-1, tpl=-1, uplat=514, ullat=0',   'alt-svc': 'h3=":443"; ma=86400',   connection: 'close',   'content-length': '241' } 

Can anyone please tell me what is going wrong. I tried to create another app, and didn't add user1(for which messages were working) added only user2 and tried sending messages, it was not working. But as soon as I added user1 to this new app, again i was able to send message through this User1's page access token.

Expecting it to work. but it didn't