facebook4j search public posts issue - facebook

I am using facebook4j to collect posts on a particular topic.
The code runs all find and I am able to search the topics.
But the result also contains the irrelevant data. Example if i search a keyword such as "messi", i am expecting the posts that contains the word "messi". But the result contains the posts of a user whose name is "messi". How can i avoid this problem?
My code is as follows
Facebook facebook = FacebookFactory.getSingleton();
facebook.setOAuthAppId("********", "*****************");
facebook.getOAuthAppAccessToken();
ResponseList<Post> results = facebook.searchPosts("messi");
for (Post result : results) {
System.out.println("************");
System.out.println(result);
}

Related

I want to display articles using gatsby-source-facebook

I want to display the data of an article using gatsby-source-facebook.
But I don't know how to write a query.
I can't find the best query at http://localhost:8000/___graphql
I make a simple website with gatsby.js.
I want to get facebook article data (posting date and text) and display it on the site.
I installed gatsby-source-facebook for that.
And changed gatsby-config.js.
→ https://www.gatsbyjs.org/packages/gatsby-source-facebook/
//`gatsby-config.js`
plugins: [
{
resolve: `gatsby-source-facebook`,
options: {
places: [`${facebookPageID}`], // Can be either a numeric ID or the URL ID
params: {
fields: 'hours, posts { message, created_time }', // See Facebooks API to see what you can query for
},
key: process.env.FACEBOOK_GRAPH_TOKEN, // You will need to create a Facebook application and go through review in order to get an API token.
},
},
],
I don't know how to write a query, so I can't get the data. (Can not be displayed.)
For example, http://localhost:8000/___graphql
query {
site {
siteMetadata {
title
         description
}
    }
}
If you enter and execute}, the title and description of the site set in gatsby-config.js enter code here will be displayed. This is normal. So how do you write a query to display facebook article data?
I searched a lot to solve this problem, but I didn't find a solution.
I only found a similar question (How to add facebook comment plugin in Gatsby?) but it could not be resolved. This question was the same as what I wrote here (https://www.gatsbyjs.org/packages/gatsby-source-facebook/).
tl;dr:
Try this:
query {
allFacebookArticles {
edges {
node {
title,
description
}
}
}
}
Explanation
That plugin stores its data into types matching the format Facebook${type} where $type is the type of thing you're pulling (in your case, articles, so it'd be FacebookArticle).
From GraphiQL, though, you should be able to see that on the sidebar on the left.
Here's an example from my current project (with some other options open):

Obtain specific data from Google Firestore using Rest API calls (HTTP-GET)

Problem
I want to retrieve specific data from Google Firestore.
It's only possible to get all of the 'Fields' data. But no specific data within fields
Example of the GET-Request:
https://firestore.googleapis.com/v1beta1/projects/edubox-49528/databases/(default)/documents/nodes/EduBox-1234567?key=[My_API_KEY]&fields=fields
As you can see, It is possible to obtain all the items in the object 'Fields'. But it is not possible to get any further into detail to obtain more specific data (test, message, nodeID, ...)
Tryouts
I have already tried:
fields=fields/test
fields=fields.test
fields=fields(test)
fields=fields/test/integerValue
...
Expected Results
I want to obtain specific data like the String / integer value of my objects in 'Fields'.
This example should return the integerValue with 30
https://firestore.googleapis.com/v1beta1/projects/edubox-49528/databases/(default)/documents/nodes/EduBox-1234567?key=[My_API_KEY]&fields=fields/test
This example should return 30
https://firestore.googleapis.com/v1beta1/projects/edubox-49528/databases/(default)/documents/nodes/EduBox-1234567?key=[My_API_KEY]&fields=fields/test/integerValue
Solution
While browsing the web, I came across Google Api Explorer:
https://developers.google.com/apis-explorer/#search/firestore/firestore/v1beta1/
When trying out some possibilities, I came across this:
https://firestore.googleapis.com/v1/projects/edubox-49528/databases/(default)/documents/nodes/EduBox-1234567?mask.fieldPaths=nodeID&fields=fields&key={YOUR_API_KEY}
This gives me the right information
but I still need a more detailed form of this answer like only the 'EduBox-1234567'
The way to retrieve a specific field is to use mask.fieldPaths. For example the following GET method:
https://firestore.googleapis.com/v1beta1/projects/edubox-49528/databases/(default)/documents/nodes/EduBox-1234567?key=[My_API_KEY]&fields=fields&mask.fieldPaths=nodeID
is going do return:
{
"fields": {
"nodeID": {
"stringValue": "EduBox-1234567"
}
}
Documentation references here and here.

I can not get the number of followers on a page

I'm trying to get the number of followers on a page. That is, obtain the number that appears in the portal as: "1363 people follow this"
I am trying to make the call as follows:
Dim urlSocialAnalitics As String =
String.Format ("https://graph.facebook.com/{0}/friends?summary=total_count&access_token={1}", pIdFanPage, pToken)
But it does not work. It's a problem for me.
I have also tried with this url:
urlSocialAnalitics = String.Format("graph.facebook.com/v2.6/{0}?fields=fan_count&access_token={1}", pIdFanPage, pToken)
But this gives me the number of Likes and not of Followers
I have read the documentation:
https://developers.facebook.com/docs/graph-api/reference/page/
But I do not see anything about it.
What is the correct call?

Facebook Graph API - Searching in public posts

Is there a way to search for 2 keywords in a public post? I want to do a full text search in all public posts.
Right now I am doing it as "https://graph.facebook.com/search?q=A+B&type=post&fields=link,message&access_token=<>.
Current Behavior: fetching posts having A or B.
Required Behavior: Fetch post have both A & B.
I have also tried POST method in Graph API Explorer. Please suggest what should I do to get results.
Other things I tried :
facebook graph api search rules. But it also seems not working, even when I tried with q=A&q=B. Only second query word is getting searched.
Use the '|' operator. In your note, 'q=A&q=B' you are reassigning the value of 'q'. The API parses the string set as the value for 'q' and uses the '|' operator to parse between. Either way you will have a tough time finding a lot of results because the 'search/post' API is now deprecated.

Retrieve User ID of Facebook App Invitor

In the context of a given Facebook app, suppose User A invited user B to start using it. Once User B accepts to use the app, is there any way to retrieve the ID of User A programmatically (via either PHP/JS SDK) ? This doesn't seem quite documented.
For what it's worth, A/B users are friends, if it's any use.
when user comes following the app request, you can get request id's using
$_GET['request_ids']
then retrieve all the request ids with which you can call graph api to get the corresponding request details like below:
if(isset($_GET['request_ids']))
{
$request_ids = $_GET['request_ids'];
}
$request_ids = explode(",", $request_ids);
foreach($request_ids as $request_id)
{
$request_object = $facebook->api($request_id);
//this $request_object have sender facebook id in the field uid_from
}
If you look here:
http://developers.facebook.com/docs/reference/dialogs/requests/
You can see the object layout. Of note is the data property:
Optional, additional data you may pass for tracking. This will be
stored as part of the request objects created. The maximum length is
255 characters.
In this object you can add your referring UserId and then when the request is claimed, you can then process it on your end.
Hope this helps.