Facebook Scribe OAuth is returning "message":"(#601) Parser error: unexpected end of query - facebook-fql

This is my java code, and the URL String which I am passing as a parameter. If I copy paste the URL on the browser it works.
String strURL="SELECT post_id, actor_id, permalink, message, impressions, type, likes, comment_info, share_count, created_time , updated_time FROM stream WHERE source_id='<srcid>'";
OAuthRequest authRequest = new OAuthRequest(Verb.GET, "https://graph.facebook.com/fql");
authRequest.addBodyParameter("q", strURL);
service.signRequest(accessToken, authRequest);
Response authResponse = authRequest.send();
System.out.println(authResponse.getBody());
Error Message -
20:12:58,986 INFO [stdout] (http-localhost-127.0.0.1-8080-2) {"error":{"message":"(#601) Parser error: unexpected end of query.","type":"OAuthException","code":601}}

Thanks cpilko. Actually it was my misinterpretation of scribe OAuth. Instead of authRequest.addBodyParameter, I should be using authRequest.addQuerystringParameter.
The code works now, and I am able to receive the response.

Related

Salesforce Integration With facebook messanger

I want to integrate SalesForce with Facebook Messenger. For this I've retrieved access token, app id , app secret. When I hit a HTTP request in developer console to send a message then there is an error.
In the given code it is not accepting messages as parameter throwing error but working without messages.
ref: https://developers.facebook.com/docs/messenger-platform/send-messages/?translation#sending_text
Httprequest req = new httpRequest();
req.setEndPoint('https://graph.facebook.com/v5.0/1798927698340/messages?access_token={PUT-ACCESS-TOKEN-HERE}');
String body = '{'+
'"recipient": {'+
'"id": "100042977199143"'+
'},'+
'"message": {'+
'"text": "hello, world!"' +
'}' +
'}';
req.setMethod('POST');
req.setHeader('Content-Type','application/json');
Http h = new Http();
HttpResponse res = h.send(req);
system.debug(res.getBody());
error message :
16:55:58:127 USER_DEBUG [16]|DEBUG|{"error":{"message":"Unsupported
post request. Object with ID 'me' 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","type":"GraphMethodException","code":100,"error_subcode":33,"fbtrace_id":"AcqDT5M6mGXSOCr4mOd3kDf"}}
actual response : success = true
This problem arises sometimes when we use invalid access token or user access token instead of page access token.

Facebook private replies response doesn't give user_id

I use the Private Replies API call to send a message in Messenger to someone commenting on a Facebook post. If the doc says I should get back the message id and the user_id, I only get the message id in response:
body:
'{"id":"m_ZpLkUdJGAoJ9WCpeROAvWJaHycesSPGVPmoNH0SXTUB8WYqRqHl0ru0y3mniMP3q7YL9rl1lfuQr0x9fyNP
Here is my API call code in ruby:
url = "https://graph.facebook.com/v3.1/" + #comment_id + "/private_replies?message=" + #trigger_message + "&access_token=" + #page_access_token
uri = URI.parse(url)
https = Net::HTTP.new(uri.host,uri.port)
https.use_ssl = true
request = Net::HTTP::Post.new(uri, initheader = {'Content-Type' =>'application/json'})
resp = https.request(request)
Why don't I get the user_id?
Facebook private replies API was supposed to return App scoped ID or ASID, though post the new app verification or around that time, they have stopped giving ASID into private reply API - most probably because they are heading towards returning Page scoped ID or PSID (PSID Migration)
Though you can still get ASID from either :
a. The webhook that could be providing comment ID, it should be providing ASID as sender_id
b. from field with parsing comment ID. This is used to parse single comment node, you can find more info here
Do keep in mind ASID to PSID migration...

Unable to get past login page using jsoup

I am unable to get the desired response using jsoup to login and scrape the referred page.
I am trying to access a page called https://localhost/private/frontpage.do , and I can see that the POST method is POST security_check which I gleaned via firebug with the parameters password=guest&username=guest&submit=.
When I use the following code I still am unable to get to the desired page.
Response res = Jsoup
.connect("https://localhost/private/security_check")
.data("j_username", "guest")
.data("j_password", "guest")
.referrer("https://localhost/private/frontpage.do")
.data("submit", "")
.method(Method.POST)
.execute();
Document doc = res.parse();
String sessionId = res.cookie("SESSIONID");
Document doc2 = Jsoup.connect("https://localhost/private/frontpage.do")
.cookie("SESSIONID", sessionId)
.get();
I received the following POST location and parameters from firebug as follows https://localhost/private/j_security_check?password=guest&username=guest&submit=
Any idea why I cant see the new page, but get a HTTP error instead in Java Exception in thread "main" org.jsoup.HttpStatusException: HTTP error fetching URL. Status=408

Facebook Private Messaging

It is said, that it is not possible to initiate new conversation through the API alone, except using Facebook's own Form integrated in the app. Is this correct, or is there some new API, which enables me to initiate a new conversation?
To reply to an existing conversation, I retrieved the conversations id using the following FQL Query "SELECT thread_id, . WHERE viewer_id={0} AND folder_id=0". Afterwards I retrieved the PageAccessToken for my app page using my user Access token, and tried to use this call:
*You can reply to a user's message by issuing an HTTP POST to /CONVERSATION_ID/messages with the following parameters [conversation id, message]. A conversation ID look like t_id.216477638451347.*
My POST Call looked like this (this is not a valid thread id): /t_id.2319203912/messages with message parameter filled. But it always said "Unknown method". Can you help me out with this one? Is there a parameter missing? I passed in the page's Access Token to call this one.
Is there some API out (except Facebook's Chat API), that I am missing, which can send private messages to users?
Edit:
What I wonder about is, that the code below only returns a single page, the application's page. Is this correct, or is there another page token required? This is what bugged me the most about the returned page.
The FacebookClient uses my UserToken to perform the next following task.
This is the code to retrieve my Page Access Token:
dynamic pageService = FacebookContext.FacebookClient.GetTaskAsync("/"+UserId+"/accounts").Result;
dynamic pageResult = pageService.data[0];
_pageId = pageResult["id"].ToString();
return pageResult["access_token"].ToString();
Now the code to retrieve my ConversationÍd:
dynamic parameters = new ExpandoObject();
parameters.q = string.Format("SELECT thread_id, folder_id, subject, recipients, updated_time, parent_message_id, parent_thread_id, message_count, snippet, snippet_author, object_id, unread, viewer_id FROM thread WHERE viewer_id={0} AND folder_id=0", FacebookContext.UserId);
dynamic conversations = FacebookContext.FacebookClient.GetTaskAsync("/fql",parameters).Result;
The following code is executed using the access token retrieved from the code above (page access token request).
Now the Code used to send the reply:
dynamic parameters = new ExpandoObject();
parameters.message = CurrentAnswer;
string taskString = "/t_id." + _conversationId + "/messages";
dynamic result = FacebookContext.FacebookClient.PostTaskAsync(taskString,parameters).Result;
return true;
I also tried it with facebook's graph API Debugger using the token, which is returned by my first part of code. But with the same error message.

Facebook API: a strange query error 601

I get this error while trying to obtain the number of shares and likes of the particular link on Facebook:
{
"error_code":601,"error_msg":"
Parser error: unexpected ''' at position 56.",
"request_args":
[{"key":"method","value":"fql.query"},
{"key":"format","value":"json"},
{"key":"query","value":"SELECT share_count, like_count FROM link_stat WHERE
url='http://www.lrinka.lt/index.php?act=main"},
{"key":"item_id","value":"5963'"}]
}
The link: http://www.lrinka.lt/index.php?act=main&item_id=5963
The API call: https://api.facebook.com/method/fql.query?format=json&query=SELECT%20share_count,%20like_count%20FROM%20link_stat%20WHERE%20url=%27http://www.lrinka.lt/index.php?act=main&item_id=5963%27
Everything works fine with other links.
You are not closing the url parameter field correctly, missing ' at the end of the URL.
Also no need for the "slashes", try the following in the fql.query console:
SELECT share_count, like_count FROM link_stat WHERE url='http:\/\/www.lrinka.lt\/index.php?act=main
Would return the same error, and this:
SELECT share_count, like_count FROM link_stat WHERE url='http:\/\/www.lrinka.lt\/index.php?act=main'
Is valid but would return zero, and finally this:
SELECT share_count, like_count FROM link_stat WHERE url='http:\\www.lrinka.lt\index.php?act=main'
Would return the result expected.
EDIT:
Based on your comment, you are trying to call https://api.facebook.com/method/fql.query?query=QUERY with the format parameter set to json..so you need to encode the query, I used encodeURI:
https://api.facebook.com/method/fql.query?format=json&query=SELECT%20share_count,%20like_count%20FROM%20link_stat%20WHERE%20url='http:%5Cwww.lrinka.ltindex.php?act=main'