Facebook Graphi API with FQL Batch Requests - facebook-graph-api

I am trying to use batch request against graph API in java. Actually it's an HTTPClient that is making a graph API request.
I tried to construct an array of batch request like this:
String query2 = "SELECT --- from tableX";
String query = "SELECT --- from tableY";
String batch_request= "[{\"method\":\"GET\",\"relative_url\":method/fql.query?query="+query+"},"+
"{\"method\":\"GET\",\"relative_url\":method/fql.query?query="+query2+"}]";
Then I URLEncode the request: String query = URLEncoder.encode(batch_request)
And pass it to graph API like this:
https://graph.facebook.com/?batch="+query+"&access_token="+accessToken
I am not getting any results :(. It returns error 500.
Any thoughts?

For batch request of fql queries, you can do this. I have tried it successfully.
//$current_user=facebook id
$query1="SELECT uid, name FROM user WHERE is_app_user=1 AND uid IN (SELECT uid2 FROM friend WHERE uid1 = $current_user)";
$query2="SELECT uid, name, work_history FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = $current_user )";
$query3="SELECT uid, name, work, education FROM user WHERE uid = $current_user";
$queries = array(
array('method'=>'GET', 'relative_url'=>'method/fql.query?query='.str_replace(' ','+',$query1)),
array('method'=>'GET', 'relative_url'=>'method/fql.query?query='.str_replace(' ','+',$query2)),
array('method'=>'GET', 'relative_url'=>'method/fql.query?query='.str_replace(' ','+',$query3))
);
$objs = $facebook->api('/?batch='.json_encode($queries), 'POST');
$objs gets json array of whole result of thre queries.
Source: https://stackoverflow.com/a/9635233/1045444

Related

NetSuite REST API with Postman: Record not found while using Suiteql

I'm trying to query some records like vendor and customer using suiteql with REST API using Postman.
The issue is that it return everytime the same error:
"Invalid search query. Detailed unprocessed description follows. Search error occurred: Record 'customer' was not found."
I tried:
differents syntax like Customer, CUSTOMER, customers, Customers, CUSTOMERS
but no change.
I added customer access to the role.
Is there something to activate while using suiteql with rest api?
Can you first try with select * from customer and see if any results are returned and then go on appending your conditions like date created greater than this year start
SELECT id, companyname, email, datecreated
FROM customer
WHERE datecreated >= BUILTIN.RELATIVE_RANGES('TFY', 'START')
AND datecreated <= BUILTIN.RELATIVE_RANGES('TFY', 'END');
NetSuite doesn't say it but for a record to be searchable, the user needs to have the following permissions:
Transactions:
Find Transaction
All the records needed
Lists:
Perform search
All the records needed
Setup:
REST WEB Services
Log in using Access Tokens or Oauth 2.0
Reports:
SuiteAnalytics WorkBook

AWS Athena + boto3: How am I supposed to execute named queries?

Concerning the following draft script I would like to know: How can I execute the named query I created?
I can access the query via the browser interface, but would like to execute it via the Session.
Here the answer is to use the client.start_query_execution(...) command. But whats the point when it is not the named query I created but instead a non-named query with the same query_string. Or am I missing something essential in how to use this?
import boto3
sess = boto3.session.Session(
region_name=region,
aws_access_key_id=ACCESS_KEY,
aws_secret_access_key=SECRET_KEY
)
athenaclient = sess.client('athena')
query_string = '''
SELECT *
FROM "ccindex"."ccindex"
WHERE crawl = 'CC-MAIN-2020-34'
AND subset = 'warc'
AND url_host_tld = 'de'
AND url_query IS NULL
AND url_path like '%impressum%'
LIMIT 20000
'''
resp = athenaclient.create_named_query(
Name='filter-ccindex-de',
Description='Filter *.de/impressum websites of Common Crawl index',
Database='ccindex',
QueryString=query_string
)
I don't think there is a direct option to pass named query to your start_query_execution method.But this can be achieved by using get_named_query which accepts Name of the named query and returns QueryString in response.
Then you can parse this response and pass QueryString to start_query_execution method.

Facebook Unity SDK - get list of friends which use the application

I'm using the Facebook Unity SDK 5.0.3 (building an Andorid player) and running into an issue trying to get a list of the friends which use the application. Have found various examples which use fql for that purpose, e.g "'/fql?q=SELECT uid, name, is_app_user, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1'", but using the last in FB.API ended up with "400 Bad Request" error.
Any ideas?
10x
Well, manage to find the solution. The problem was using FQL from JavaScript documentation example as is. The following code does the work:
var fqlQuery = "/fql?q=" + WWW.EscapeURL("SELECT uid, name, is_app_user, pic_square FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1");
FB.API(fqlQuery, Facebook.HttpMethod.GET, GetFbFriendsCallback);
The GetFbFriendsCallback code can be found in Smash Friends sample application provided with SDK.

Getting users friend data using FB Graph API

I am attempting to access a user's friends work and education history using the Graph API. I have included both permissions in the auth dialogue. I have tried accessing them using FQL but have had no luck.
try{
$fql = "select friends_education_history from permissions where uid=" . $user;
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
}
catch(Exception $o){
d($o);
}
}
I'd prefer to access the info without using FQL but at this point, I need to figure out ANY way. Is there a way to do something like this:
if($user_id) {
try {
$friends = $facebook->api("/me/friends");
}
catch(Exception $o){
d($o);
}
}
?>
And then call the respective variables?
Your FQL query would look something like this:
SELECT education,work from user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
Above query will fetch all education and work objects from friends of the logged in user.
SELECT education,work from user WHERE uid = <YOUR FRIENDS USER ID>
Above query will get education and work for just the one user id you provide
Hope this helps!
The User graph api object has fields education and work.
Permissions user_education_history & friends_education_history are required for the first, user_work_history & friends_work_history for the second.
These fields are optional & a user can restrict their visibility via her profile page, so even having granted the permissions the api may return nothing.
Use the Graph api explorer to have a play.

Get my UID using FQL

I need to get my UID using a simple FQL query, for some reason it returns an empty page.
This is my query:
https://api.facebook.com/method/fql.query?query=SELECT uid FROM user WHERE uid=me()
me() returns the current connected user. So you need to append an access_token:
https://api.facebook.com/method/fql.query?query=SELECT uid FROM user WHERE uid=me()&access_token=XXXXXX
P.S.: Facebook has just released a Graph API endpoint to query FQL fql, so you should be able to do something like:
https://graph.facebook.com/fql?q=SELECT uid FROM user WHERE uid=me()&access_token=XXXXXX
(unfortunately, for some reason it's not working on the Facebook Graph Explorer)