PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label facebook-graph-api. Show all posts
Showing posts with label facebook-graph-api. Show all posts

Thursday, November 3, 2022

[FIXED] How to extract insights from facebook action dataset and covert all values into each column

 November 03, 2022     dictionary, facebook-graph-api, for-loop, json, pandas     No comments   

Issue

Here is dataset as shown in below and I want to convert it into each data column with their values as

i want to append the values in columns and I tried this code

y = data['actions'].apply(lambda x: str(x).replace("'",'"'))
json.loads(y[0])
json.loads(y[1])

it gives output like as shown in below

[{'action_type': 'post_reaction', 'value': '2'},
 {'action_type': 'link_click', 'value': '42'},
 {'action_type': 'comment', 'value': '1'},
 {'action_type': 'post_engagement', 'value': '45'},
 {'action_type': 'page_engagement', 'value': '45'},
 {'action_type': 'onsite_conversion.lead_grouped', 'value': '6'},
 {'action_type': 'leadgen_grouped', 'value': '6'},
 {'action_type': 'lead', 'value': '6'}]

[{'action_type': 'onsite_conversion.post_save', 'value': '1'},
 {'action_type': 'post_reaction', 'value': '4'},
 {'action_type': 'link_click', 'value': '62'},
 {'action_type': 'post_engagement', 'value': '67'},
 {'action_type': 'page_engagement', 'value': '67'},
 {'action_type': 'onsite_conversion.lead_grouped', 'value': '6'},
 {'action_type': 'leadgen_grouped', 'value': '6'},
 {'action_type': 'lead', 'value': '6'}]

I want to create the dataframe that gives each action type as column and append their values in respective columns and if there is no value it appends zero like

| post_reaction| link click | comment |---------------------
| --------     | -----------|---------|
| 2            | 42         |1        |
|  4           | 62         |67       |


Solution

If no lists in data use ast.literal_eval for converting first and then with list comprehension create DataFrame:

import ast

y = data['actions'].apply(ast.literal_eval)

df = pd.DataFrame([{z['action_type']:z['value'] for z in x} for x in y]).fillna(0)

If lists in data use only list comprehension:

df = (pd.DataFrame([{z['action_type']:z['value'] for z in x} for x in data['actions']])
        .fillna(0))


Answered By - jezrael
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I download a video from Facebook using GraphAPI?

 November 03, 2022     facebook, facebook-graph-api, video     No comments   

Issue

I want to download a video from facebook to the clients local drive. I saw a few browser plugins and Facebook apps that are able to that and I was wondering how it can be done using the GraphAPI or in any other way.


Solution

First, you get the Graph API object. If the object is public, it's simple, just get https://graph.facebook.com/10151651550011063. (Where the number is the object's ID, equal to the ?v=OBJECTID in the facebook video URL.)

If the object is not public, you need a valid access_token, and the Graph API url becomes something like https://graph.facebook.com/10151651550011063?access_token=DFSDSGSFDGFGDSblabla

Then, in the Graph API object, you'll find the video download link under source.



Answered By - knutole
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to access all draft campaigns with the Facebook marketing API?

 November 03, 2022     facebook, facebook-ads-api, facebook-graph-api, facebook-marketing-api     No comments   

Issue

I'm trying to list all of my draft campaigns using the Facebook marketing API. By default, it seems, only non-draft (published?) campaigns are listed when calling

curl -i -X GET \
 "https://graph.facebook.com/v12.0/act_12345/campaigns?fields=id,name&access_token=<mytoken>"

When looking at the code of the facebook-python-business-sdk, there are multiple references to unpublished content type, which makes me think that there should be a way to list all unpublished campaigns. So my question is how can I list all campaigns, published and unpublished?

I know this question is a duplicate (see here, here, and here) but I'm asking it again since it has not been answered and I'd like to put out a bounty for a helpful response.


Solution

I believe the only way to get draft campaigns is below:

  1. You should get all addrafts. On my account I have only 1 addraft that contains all draft campaigns, but maybe you can have more. URL for getting addrafts:

https://graph.facebook.com/v12.0/act_<ad_account_id>/addrafts?access_token=<access_token>&fields=name,ad_object_id,id

  1. Now you can get addraft_fragments. You can see all draft fragments of your ad_account (campaigns, adsets, ads), but you can easily find here what you want. URL for getting addraft_fragments:

https://graph.facebook.com/v12.0/<addraft_id>/addraft_fragments?access_token=<access_token>&fields=name,id,ad_object_id,ad_object_type,budget,ad_object_name,values



Answered By - Oleksii Tambovtsev
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to further filter Facebook Graph API query on Graph API Explorer for my ad account?

 November 03, 2022     facebook, facebook-ads-api, facebook-graph-api, facebook-insights, facebook-marketing-api     No comments   

Issue

I'm trying to get the ad spend and mobile app installs for my app using the Facebook Graph API v2.11 for marketing. In the Graph API Explorer, when I try

/act_<my account>/campaigns?fields=insights{actions,spend}&time_range={'since':'2017-07-07','until':'2017-12-12'}

In the output, under "insights", I get an object of this type:

    "data": [
      {
        "actions": [             
          {
            "action_type": "comment",
            "value": "3"
          },
          {
            "action_type": "like",
            "value": "33"
          },
          {
            "action_type": "link_click",
            "value": "1531"
          },
          {
            "action_type": "mobile_app_install",
            "value": "1049"
          }
        ],
        "spend": "8621.03",
        "date_start": "2017-10-28",
        "date_stop": "2017-11-26"
      }
    ]

If I want it to fetch only the actions where action type is "mobile_app_install", how can I further filter my query?


Solution

There is possible to filter that on Facebook side just call it like that:

/act_<yourAdAccount>/insights
  ?level=campaign
  &fields=actions,spend
  &time_increment=all_days
  &time_range={'since':'2017-07-07','until':'2017-12-12'}
  &filtering=[{field: "action_type",operator:"IN", value: ['mobile_app_install']}]
  &use_account_attribution_setting=true


Answered By - Vanley
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do you get the total likes for a URL (Likes and Shares)?

 November 03, 2022     facebook, facebook-graph-api, facebook-like, facebook-social-plugins     No comments   

Issue

The "Likes" plugin that I've dropped on my page displays both the number of times the button has been directly clicked, as well as the number of times the page URL has been shared or the Like has been commented on.

When I use the Graph API to check out my object though, it only shows the number of direct "Like" clicks. Here is an example object:

{
   "id": "17678692xxxxxxx",
   "name": "The Dali Lama Returns",
   "picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/161984_176786925772923_6855xxxxxxx.jpg",
   "link": "http://mysite.com/8/the-dali-lama-returns",
   "likes": 1,
   "app_id": 478xxxxxxx,
   "category": "Unknown",
   "is_published": true,
   "description": "The Dali Lama will speak, and we will listen.",
   "about": "The Dali Lama will speak, and we will listen.",
   "can_post": true
}

This means that after someone has clicked my like button, and written a comment about the like, the the button will display a count of "2", but my object will only display a count of one.

Is there a way to get the complete "Like" count that the button displays on my page?


Solution

I found two ways of doing this. The new way utilizing the graph api appears to be to be to use fql, as the following request shows:

https://graph.facebook.com/fql?q=SELECT url, normalized_url, share_count, like_count, comment_count, total_count, commentsbox_count, comments_fbid, click_count FROM link_stat WHERE url='http://mysite.com/8/the-dali-lama-returns'

The old way, with the Rest API which is in the process of being deprecated:

link.getStats()

https://developers.facebook.com/docs/reference/rest/links.getStats/



Answered By - HelpMeStackOverflowMyOnlyHope
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to revoke all permission on facebook api using rest api

 November 03, 2022     facebook-graph-api     No comments   

Issue

I trying to revoke all permission on withdrawl user facebook document said will be conducted by calling Url with 'user access token or app access token

https://graph.facebook.com/me/{user_id}/permissions

but i cant attaching user access token in this request, but i can attach app access token in query params. so i requested this url with app access token, but response message is "An active access token must be used to query information about the current user."

Can I really request it with an app access token?


Solution

/me/{user_id}/ makes no sense as request path here.

You either use /me, in combination with a user or page token - then that alias will resolve to the actual ID of the entity the token belongs to.
Or you use an app-scoped user ID directly.

If you want to perform any actions on a user account using the app access token, then you must use the second version.

https://graph.facebook.com/{user_id}/permissions?access_token={app_access_token}


Answered By - CBroe
Answer Checked By - Katrina (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I post a photo and caption in the same publish on a facebook group api using FormData and axios?

 November 03, 2022     facebook-graph-api, javascript, typescript     No comments   

Issue

Someone could help me, I'm trying to send a photo and caption into a group, but isn't working! I'd like send the photo that I recieve as base64 and send to a facebook group api.

What I'm doing? I got the base64 then convert into buffer and write it on a local disk, then I read it into a formdata. I load the data into a form this way =>

const form = new FormData();
    const fileContent = Buffer.from(url as any, 'base64');

    fs.writeFile('../tmp', fileContent, (err) => {
      if (err) return console.log(err)
    })


form.append('groupId', groupId)
 form.append('caption', caption) 
form.append('image ', fs.createReadStream('../tmp'))

In below is the axios configurations and request

 await client.post(`${config.facebook.BASE_URL}/${groupId}/photos`, form, {
  headers: {
    ...form.getHeaders(),
    Authorization: `OAuth ${config.facebook.token}`,
    'content-type': 'multipart/form-data',
    file_type: "image/jpeg",
  }

})

Note: This way I got the Error: Request failed with status code 500


Solution

I already resolved this although I changed de way that the file came to me, instead of receiving the image in base64 I'm receiving a signed url from google storage, and on the form.append, it's necessary to pass the name and the extension of the file, like this => form.append('source', image, 'file.jpg'); of course together with the other params and axios' configurations



Answered By - Jhonatan Sena
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Where to get product-catalog-id

 November 03, 2022     facebook-graph-api     No comments   

Issue

I am using Facebook marketing API 3.3 version to read product feeds but I don't know where can I get the product-catalog-id.Here is the URL :

GET /v3.3/{product-catalog-id}/product_feeds

Solution

You can get your product-catalog-id in the settings page of catalog page (https://www.facebook.com/products/catalogs)

Image



Answered By - Eduardo Mendoza
Answer Checked By - Mary Flores (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] how to display latest recent posts in my facebook page to my website

 November 03, 2022     facebook, facebook-c#-sdk, facebook-graph-api, php     No comments   

Issue

i have page on Facebook and I want to display latest 5 posts from my feed/wall on a page to my website. How to do this? I found this solution.. it is easy

https://developers.facebook.com/docs/reference/plugins/like-box/

and someone guide me to use facebook api and do it myself what is the best way?

I use php mysql to build this site


Solution

Here is the PHP code. You need to place this in your template.

<ul>
<?php
//function to retrieve posts from facebook’s server
function loadFB($fbID){
    $url = "http://graph.facebook.com/".$fbID."/feed?limit=3";
    // Update by MC Vooges 11jun 2014: Access token is now required:
    $url.= '&access_token=YOUR_TOKEN|YOUR_ACCESS_SECRET';// *

    //load and setup CURL
     $c = curl_init($url);
     curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    //get data from facebook and decode JSON
     $page = json_decode(curl_exec($c));
    //close the connection
     curl_close($c);
    //return the data as an object
     return $page->data;
}

/* Change These Values */
// Your Facebook ID
 $fbid = "190506416472588";
// How many posts to show?
 $fbLimit = 10;
// Your Timezone
date_default_timezone_set("America/Chicago");


/* Dont Change */
// Variable used to count how many we’ve loaded
 $fbCount = 0;
// Call the function and get the posts from facebook
 $myPosts = loadFB($fbid);


//loop through all the posts we got from facebook
foreach($myPosts as $dPost){
    //only show posts that are posted by the page admin
    if($dPost->from->id==$fbid){
        //get the post date / time and convert to unix time
         $dTime = strtotime($dPost->created_time);
        //format the date / time into something human readable
        //if you want it formatted differently look up the php date function
         $myTime=date("M d Y h:ia",$dTime);
        ?>
        <ul>
            <li><?php echo($dPost->message) . $myTime; ?></li>
        </ul>
        <?php
        //increment counter
         $fbCount++;
        //if we’ve outputted the number set above in fblimit we’re done
         if($fbCount >= $fbLimit) break;
    }
}
?>
</ul>

Two things you must do for working out this script.

  1. Make sure your server is cURL enabled

  2. You will have change the Facebook ID in the script by yours.

* You can get the access token this way:

$token = 'https://graph.facebook.com/oauth/access_token?client_id='.APP_ID.'&client_secret='.APP_SECRET.'&grant_type=client_credentials';
$token = file_get_contents($token); // returns 'accesstoken=APP_TOKEN|APP_SECRET'


Answered By - Okky
Answer Checked By - Mary Flores (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to Remove Facebook Comments Plugin From A Blogger Blog

 November 03, 2022     blogger, facebook, facebook-graph-api, html     No comments   

Issue

I have a blogger blog

I want to completely remove Facebook Comments Widget/Plugin and replace it with Disqus since I know that viewers would prefer Disqus more than Facebook plugin.

I tried a lot of times to remove facebook plugin but even if I remove it some or other problems keep rising. Like I won't be able to add Disqus comments or neither Google comments work.

The theme I am using is a 3rd party designed theme and the developer and his website is nowhere to be found anymore. His website was closed and he can't be contacted from anywhere else.

Though I have modified a lot of parts, here is the theme of my blog:

pastebin.com/EJieAgfe

The above theme is directly downloaded from my blog. Please help me.


Solution

Click anywhere inside your code area, press CTRL + F, search for <body> and remove the next block of code

<div id='fb-root'/>
<script type='text/javascript'>
function fb_load(){var d=document.createElement(&quot;script&quot;);d.src=&quot;//cdn.rawgit.com/tutorialku/usagilabs/master/fb_us.js&quot;,document.body.appendChild(d)}window.addEventListener?window.addEventListener(&quot;load&quot;,fb_load,!1):window.attachEvent?window.attachEvent(&quot;onload&quot;,fb_load):window.onload=fb_load;
</script>


Answered By - user6144987
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to replace all users in a Custom Audience using the Facebook Marketing API

 November 03, 2022     facebook-graph-api, facebook-marketing-api, facebook-python-business-sdk, python     No comments   

Issue

I'm trying to work out how to replace the users in a Custom Audience. I'm able to delete and create a new audience, but ideally I just want to update the existing audience as it's shared with other accounts.

I think I may be able to do this using create_users_replace but Im getting the error message:

facebook_business.exceptions.FacebookRequestError:

  Message: Call was not successful
  Method:  POST
  Path:    https://graph.facebook.com/v13.0/23850060704540982/usersreplace
  Params:  {}

  Status:  400
  Response:
    {
      "error": {
        "message": "(#100) The parameter session is required",
        "type": "OAuthException",
        "code": 100,
        "fbtrace_id": "AOJ9p0Hd1Kla4NRlkhOnHIQ"
      }
    }

Here's the code I'm trying to use:

from collections import UserList
from facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.customaudience import CustomAudience
from facebook_business.api import FacebookAdsApi

test_id = '2385040704549815'

api = FacebookAdsApi.init(access_token=access_token)

session_id = '123456789'
session = {
            'session_id':session_id, 
            'batch_seq': 1, 
            'last_batch_flag':False, 
            }

# List of hashed email addresses (SHA256)
test_audience_list = ["8b84db83027ecd2764ac56dd6ed62aa761ea315e0268c64e34104a6536f"]

# I can add a list of users to a custom audience using this
CustomAudience(test_id).add_users(schema="EMAIL_SHA256", users=test_audience_list)

# I'm unable to replace all users with a new list
CustomAudience(test_id).create_users_replace(fields=None, params=None, batch=None)

I've also tried including the session parameter:

CustomAudience(test_id).create_users_replace(fields=None, params=None, batch=None, success=None, failure=None, session=session)

but then I get an error about an unexpected keyword argument 'session'.

Is it possible to replace all users in a Custom Audience using a new list? What would be the best way to do this?


Solution

This one worked for me:

from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.customaudience import CustomAudience

from random import randint

email_sha265 = '<sha265>'
list_id = '<list_id>'

client = FacebookAdsApi.init(
                _app_id,
                _app_secret,
                _access_token
              )
audience = CustomAudience(list_id)

session_id = randint(1000000, 9999999)

params = {
    "session": {
        "session_id": session_id,
        "batch_seq":1,
        "last_batch_flag": "false"
    },
    "payload": { 
        "schema":"EMAIL_SHA256", 
        "data":
        [
          email_sha265
        ]
    }
}

# make the call
audience.create_users_replace(params=params)

Response:

<CustomAudience> {
    "audience_id": "<list_id>",
    "invalid_entry_samples": {},
    "num_invalid_entries": 0,
    "num_received": 1,
    "session_id": "4847542"
}

Check this source code for more information:

https://github.com/facebook/facebook-python-business-sdk/blob/main/facebook_business/adobjects/customaudience.py

And the FB Docs:

https://developers.facebook.com/docs/marketing-api/audiences/guides/custom-audiences/#replace-api



Answered By - Moritz
Answer Checked By - Cary Denson (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I interact with a facebook app page without always generating a token

 November 03, 2022     facebook, facebook-graph-api     No comments   

Issue

I'm making an API to post to our companys facebook page but all documentation and request errors require me to get a page access token but this is supposed to run on the server and its a bit inconvenient for our dev team to every 2 months have to generate a new token and restart the app so my question is if its possible to use the app id and secret only or get a permanent token?


Solution

I found out a couple time after posting this question here at stackoverflow that facebook has system users that allow you to generate tokens for server side services that dont need a specific user data.

https://developers.facebook.com/docs/marketing-api/system-users

You will need to make your sys user admin to make posts and what not.



Answered By - DeadSec
Answer Checked By - Terry (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to send comment in my facebook page post using graph api?

 November 03, 2022     facebook-graph-api, python, python-3.x     No comments   

Issue

I am trying to send comment in my facebook page post using graph api. Here is my code,

    try:
        x=graph.put_object(page, 'photos', message=msg, url=url) # It returns like {'id': '5887079443594804', 'post_id': '10039484545559233_588705678675675679394804'}
    except:
        print("Error while trying to send the midia file.")

    try:
        python_obj = json.loads(x)
        y=graph.put_object(python_obj[post_id], 'comments', message=msg)
    except:
        print("Error while trying to send the comment.")

I get

Error while trying to send the comment


Solution

You are using the wrong method to add a comment. The correct method is

graph.put_comment(object_id='post_id', message='...')

You can read more in the documentation.

Edit: the response returns you a dictionary, not JSON, so json.loads() fails. Change it to

try:
    y=graph.put_object(x['post_id'], 'comments', message=msg)


Answered By - Abhinav Mathur
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can i find out facebook API version

 November 03, 2022     facebook-graph-api     No comments   

Issue

I have an app id and secret of a facebook app. But I am not owner, how can I find out its app version?

I tried to go through fb graph api document but it did not work.


Solution

According to a somewhat relatable FAQ, you can check the facebook-api-version header in the response to determine the API version that had been used to process the request.

Currently (as of December 26, 2015), the oldest active version is 2.0, so any unversioned calls will use the 2.0 API (until August 2016). The changelog can be found here



Answered By - Chris Forrence
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I get the events for a Facebook page?

 November 03, 2022     facebook, facebook-graph-api     No comments   

Issue

Using the latest version (2.12) of the Facebook API I'm trying to get (public) events for a page, using the Graph API Explorer.

However, I can't seem to get it working:

enter image description here

When I hover over the greyed out "id" or "name" on the left, it says "Field is empty or disallowed by the access token".

Now the page I'm using as an exmple here is Techcrunch, and they have plenty of events coming up. So "empty" doesn't seem to be the issue.

On the "disallowed" side I've checked the API reference on https://developers.facebook.com/docs/graph-api/reference/page/events/.

However, I can't seem to find any issue here either. It says "Reading Page events requires a valid Page access token or User access token with basic permissions.".

What am I missing here? Any hints are greatly appreciated!


Solution

Visit https://developers.facebook.com/docs/graph-api/changelog/breaking-changes#pages-4-4

Currently Facebook is not returning events for pages using Pages API unless you use an user accesss token and that user has been invited to any of the events of the page or is attending/interested in any of the events of the page.



Answered By - unknown_b
Answer Checked By - Candace Johnson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to delete Instagram posts using API

 November 03, 2022     facebook-graph-api, instagram-api, instagram-graph-api     No comments   

Issue

I want to delete a specific post on Instagram with JavaScript using API

I tried how to remove a post from the following document.

https://developers.facebook.com/docs/graph-api/reference/v13.0/post#deleting

but, I got the following error.

Unsupported delete request. Object with ID '{post_id}' 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

Solution

Instagram does not yet support delete via their API. Please see the content publishing API.



Answered By - Geoffrey Bourne
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to get the total number of posts in a Facebook page with Graph API?

 November 03, 2022     facebook, facebook-graph-api     No comments   

Issue

I am using Facebook Graph API to crawl information from public page. The current problem is how to get the total number of posts on a Facebook page. If we go to /{page-id}/posts, it will only return 25 posts posted on this page, and no summary information mentioned the page's fields. I have check the previous answer, it seems that the only way is to count the number of items of each link in next and get total number. But it is very inefficient. Is there any method that can directly get the total post on a page other than FQL?


Solution

Facebook doesn't actively count the number of posts a page has made; depending on the page it could be an astronomical number.

You would have to get all the posts and count through them yourself. I would use something like this.

{PAGE}/posts?fields=id&limit=250

It will return the smallest possible data set you need. You can't go above 250, you could with FQL but not with v2.1. Also you don't want FEED because that is an aggregation of the Page's Posts and the Posts made to the page by other users. This will return an object like this.

{
 "data" : [
  PostData
  ... ],
 "paging" : {
  ...
  "next" : CursorURL
 }
}

This is the cursor URL so you can step down the groups of 250 posts in reverse chronological order.

You can shortcut the counting by incrementing 250 every time you get a new cursor that also returns more posts. You will only have to count and add the results in the set with the 2nd to last cursor since the last cursor will return an empty data array.



Answered By - Frank D
Answer Checked By - David Goodson (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I get all photos in one post using Graph API?

 November 03, 2022     facebook, facebook-fql, facebook-graph-api, post     No comments   

Issue

  {
    "id": "11882030_4952296803730", 
    "from": {
      "name": "xxx", 
      "id": "11882030"
    }, 
    "message": "test", 
    "picture": "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash4/408410_4952294483672_298434229_s.jpg", 
    "link": "https://www.facebook.com/photo.php?fbid=4952294483672&set=pcb.4952296803730&type=1&relevant_count=2", 
    "icon": "https://fbstatic-a.akamaihd.net/rsrc.php/v2/yx/r/og8V99JVf8G.gif", 
    "actions": [
      {
        "name": "Comment", 
        "link": "https://www.facebook.com/11882030/posts/4952296803730"
      }, 
      {
        "name": "Like", 
        "link": "https://www.facebook.com/11882030/posts/4952296803730"
      }
    ], 
    "privacy": {
      "description": "Friends", 
      "value": "ALL_FRIENDS", 
      "friends": "", 
      "networks": "", 
      "allow": "", 
      "deny": ""
    }, 
    "place": {
      "id": "471607792876974", 
      "name": "TTT", 
      "location": {
        "street": "", 
        "zip": "", 
        "latitude": x, 
        "longitude": x
      }
    }, 
    "type": "photo", 
    "status_type": "mobile_status_update", 
    "object_id": "4952294483672",
    "application": {
      "name": "Facebook for iPhone", 
      "namespace": "fbiphone", 
      "id": "6628568379"
    }, 
    "created_time": "2013-01-17T01:29:59+0000", 
    "updated_time": "2013-01-17T01:29:59+0000", 
    "comments": {
      "count": 0
    }
  }

As above, I posted a status with two photos. I can get the first photo's thumb URL in picture and the relevant link & count information in link.

But how can I get each photo's specific URL?


Solution

FQL often provides more information than Graph API. You have to use the attachment parameter of the stream FQL table to get all the attached photos.

SELECT attachment FROM stream 
 WHERE source_id = me() 
   AND post_id="11882030_4952296803730"

Result:

{
  "data": [
    {
      "attachment": {
        "media": [
          {
            "href": "https://www.facebook.com/photo.php?fbid=471082296...", 
            "alt": "", 
            "type": "photo", 
            "src": "https://fbcdn-photos-a.akamaihd.net/hphotos-ak-ash3/5826...", 
            "photo": {
              "aid": "4391039135", 
              "pid": "439104482145", 
              "fbid": 471507, 
              "owner": 102832, 
              "index": 1, 
              "width": 485, 
              "height": 172, 
              "images": [
                {
                  "src": "https://fbcdn-photos-a.akamaihd.net/hph...", 
                  "width": 130, 
                  "height": 46
                }
              ]
            }
          }
        ], 
        "name": "", 
        "caption": "", 
        "description": "", 
        "properties": [
        ], 
        "icon": "https://fbstatic-a.akamaihd.net/rsrc.phpjk.gif", 
        "fb_object_type": "album", 
        "fb_object_id": "4391044992857139135"
      },
      { 
        ... //Photo 2
      }
    }
  ]
}


Answered By - Stéphane Bruckert
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How To Get User Name From Facebook Unity SDK

 November 03, 2022     facebook, facebook-graph-api, unity3d     No comments   

Issue

I am new in unity and trying to integrate Facebook unity SDK. But i am not able to find current logged-in user name. It will return only userId and accessToken. How to get login name after FB.Login("email")


Solution

After you login, you can get the name with:

FB.API("me?fields=name", Facebook.HttpMethod.GET, <your callback here>);


Answered By - Brian Jew
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I validate Facebook post IDs

 November 03, 2022     facebook, facebook-graph-api, facebook-wall, validation     No comments   

Issue

Assume a facebook game that rewards users with virtual-currency usable in the game for posting events from the game on their wall.

Using the IFrame method, I get on the client a JavaScript callback with the { post_id: 'some id' } when the user completes the post successfully, and life is good.

While the post takes place on the client, I have to address the server and commit the reward for the user, providing the server with the post-id, and that is done using some form of JSONP HTTP request.

Stripping away the defense mechanisms against abuse that make sure that users will not overdo with posts and annoy all their friends with the game, lets focus on the problem:

  • since server calls can be easily mocked using utils like curl or fiddler, after signing the request and all, I still need to make sure that the post-id that came in this request is in deed a real post_id that came from facebook, and that this post is in-deed visible on the user's wall - at least for his friends...

(because, no, post as private post that only you can see should not reward you with virtual-currency)

What's the best way to do that?


Solution

@CBroe is absolutely right: Facebook Policies (specifically Section IV, Item 1) prohibit the functionality you describe.

Breaking a policy and circumventing restrictions (which is another item against the policy...) is never the "best way" to do anything. But... what you describe is possible. I'd explain how but it's probably also against Stack Exchange policy to do so:

3 Subscriber Content

[...]

Subscriber represents, warrants and agrees that it will not contribute any Subscriber content that [...] (c) infringes any intellectual property right of another or the privacy or publicity rights of another[.]

Just know it's possible, maybe figure out how to do it for the satisfaction, and then move on without implementing what you ask.



Answered By - josaphatv
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home
View mobile version

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing