For my graduation I have to develop a Java application for opinion mining on Facebook.
The topic is opinion mining on the Facebook pages of political parties to compare the opinion of Facebook users to official polls. So it's only public data on public pages.
I'm using the restfb library to obtain data. I want to obtain posts and comments.
Until now I'm successful in getting the data, but there are some issues which I don't understand:
I'm getting data using graphApi calls with URL parameters. With the limit parameter I get a different amount of posts when using an access token provided by the graph explorer, than I get when using an access token provided by logging in with Facebook App data (appId, appSecret). Why is that?
Compared to the posts listed on the Facebook Feed, some (public) posts aren't returned at all. What's the reason for this? (As i said, I'm using the limit parameter in a graphApi call)
Some of the returned posts seem corrupt. When using the graph explorer the posts look like the following: (I erased to omitted fields)
{
"id": "id omitted",
"from": {
"name": "name omitted",
"category": "Political party",
"id": "id omitted"
},
"story": "\"\" on their own link.",
"type": "status",
"created_time": "2012-10-09T11:13:09+0000",
"updated_time": "2012-10-09T11:13:09+0000",
"comments": {
"count": 0
}
},
Processing these posts always throws an exception because many data are missing such as comments, likes etc...
Are these corrupted entries or maybe deleted posts?
Related
I'm working on a project in which I'm creating (POST) a book. Once the book is created, a unique bookId is generated and the response looks something like this:
{
"bookId":"123pqr",
"author":"Abc",
"title": "Book1"
}
I have one GET request which basically fetches the book details using bookId - http://localhost:port/{bookId}.
I'm trying to get this above URL whenever I create a book so that my response should look like this:
{
"bookId":"123pqr",
"author":"Abc",
"title": "Book1"
"url": "http://localhost:port/{bookId}"
}
So that if a user clicks on the URL, the user should be navigated to a GET request http://localhost:port/{bookId}. I think I can just hardcode a string "http://localhost:port/" and then append bookId to it and provide the same in response. However, I'm not sure how to set the request type as GET when the URL is clicked. Also, is there a better way to avoid harcoding? Could someone please help? Thanks in advance!
You do not need to specify anything to consider a URL as a GET.
This is natively part of every browser.
However, you could think a bit further and use HATEOAS which specifies the kind of relationship for a specific href
Your response would look like the following where self is standardized to be a GET request since it's the retrieval of the resource
{
"bookId":"123pqr",
"author":"Abc",
"title": "Book1"
"_links": {
"self": {
"href": "http://localhost:port/{bookId}"
}
}
}
More information can be found here
Spring HATEOAS which BTW can also help with building the URI and thus no need to hardcode localhost and port making your app dynamic enough
Environment: Cloud Foundry Trail
I deployed my business & approuter applications using help
Now my requirement is get below user profile after XSUAA login.
Is there any API to get user profile details?
{
"lastName": "XXXXX",
"passwordStatus": "enabled",
"mail": "XXXXX#gmail.com",
"displayName": "XXXX XXXX XXXXX",
"uid": "XXXXXX",
"photoUrl": "https://www.gravatar.com/avatar/760fcd379cf60090e1e27b052f9e49bd?d=mm",
"firstName": "XXXX",
"contactPreferenceEmail": "unknown",
"status": "active",
"spUsersAttributes": [
{
"ServiceProviderName": "sapcpcf",
"NameID": "XXXXX",
"Status": "ACTIVE",
"ActivationTime": "20181026050006Z"
}
]
}
Updated answer:
The IdP used by default on Cloud Foundry does not use SAML. Thus, mapping of SAML attributes does not work. Use the approach listed below only when using an IdP that supports SAML.
Instead, when using the default IdP, there three fields (given_name, family_name, email), that can be accessed as follows:
AuthTokenAccessor.getCurrentToken().get().getJwt().getClaim("email").asString();
Original answer:
you can do the following:
First, add a role template to your xs-security.json you used to configure your XSUAA instance like this:
{
"name": "Authenticated",
"description": "All authenticated users",
"attribute-references": [
"given_name",
"family_name",
"email"
]
}
Note that you need to recreate the XSUAA instance with the new config in order for this change to work.
Now, in the roles section of your Identity Provider (if you use the default Cloud Foundry IdP you can find that under the "Security" tab on the left of the Cloud Cockpit), you can configure how these fields should be filled. Choose "Identity Provider" there.
Of course make sure that this role is assigned to every user.
Finally, you read the information using the UserAccessor:
final User currentUser = UserAccessor.getCurrentUser();
currentUser.getAttribute("email");
This should help you get the necessary information!
Currently, there is no dedicated API to get all of these user profile details. You can use the AuthTokenAccessor to access the current JWT which should contain this information.
The new facebook api allows us to get reactions on a post on a page, for this fb has created a reactions edge
I am able to extract data from this edge by simple hitting post-id/reactions from the graph api explorer.
Here is the graph api request :-
1497117777255241_1526440124323006/reactions
and the response data
{ "data": [
{
"id": "100008182891350",
"name": "Harsh Sharma",
"type": "LOVE"
} ], "paging": {
"cursors": {
"before": "TVRBd01EQTRNVGd5T0RreE16VXdPakUwTmpRd01EQTROalk2TnpnNE5qUTRNRE0zT1RFek16RXkZD",
"after": "TVRBd01EQTRNVGd5T0RreE16VXdPakUwTmpRd01EQTROalk2TnpnNE5qUTRNRE0zT1RFek16RXkZD"
} } }
now i try to do the same using the java rest fb api in which I first extract the post and then using that object I call the get reactions method on it but I dont get any data.
Here is the sample code for the same :-
reactionsCount=post.getReactionsCount();
System.out.println("post id-->"+post.getId()+" reactions--->"+post.getReactionsCount());
reactionsObj=post.getReactions();
for the above post id : there is a reaction on it but I am getting the reaction count as zero via restFB, but I am getting data from graph api.
The reactionObj is also null every time (obtained via reactionsObj=post.getReactions();
)
if(reactionsObj!=null)
{
System.out.println("bring it on reactions-------");
for (ReactionItem reactionListItem : reactionsObj.getData())
{
reactionsMap.put("id", reactionListItem.getId());
reactionsMap.put("name", reactionListItem.getName() );
reactionsMap.put("type",reactionListItem.getType() );
}
}
I am getting posts/comments/likes successfully, only the reactions edge is creating problems.
Please let me know where I am going wrong.
Edit
Connection<Post> postSearch =FacebookClientBean.getFacebookclient().fetchConnection(pageId+"/feed", Post.class);
Collected solutions from the comments:
to get reactions on a Post you have to add the field in the request like this:
fetchConnection(pageId+"/feed", Post.class, Parameter.with("fields","reactions.summary(1)"));
An error message with the content requires version v2.6 or higher is a hint the wrong Graph API version is used to request the node.
Select the correct Version in the DefaultFacebookClient constructor:
new DefaultFacebookClient(accessToken, Version.VERSION_2_6);
I have a problem with my appilication when am perfoming bulk update's and create's.
I have very huge rest pay load which contains 1000 fields and with 10000 update at a time. After submitting the request data will be save in db with jdbc procedure.
Now here we are facing perfomance issue.
i have to design a bulk api to reslve this perfomance issue.
i searched existing bulk api by Sales force and Telerik.But not clear about their implemention.
How do i design a my own bulk REST API in java for bulk update's and create's.
Which design patterns should i take into consideration?
It will be helpful for me, if any body could answer me.
Thanks in advance.
An often used term in REST is "Collection Resource".
Consider a system that stores invoices. The collection resource for them could have the URL
/resources
while a single invoice with ID 123 could have the URL
/resources/123
Adding a new invoice to the collection would be done using
POST /resources
Content-Type: application/json
{
"customer": "CUS-123",
"amount": 1.43,
"paided": false
}
The server would store it and assign an ID to it.
To store more than one invoices in one request, it would make sense to post an array:
POST /invoices
Content-Type: application/json
[
{
"customer": "CUS-123",
"amount": 1.43,
"paided": false
},
{
"customer": "CUS-456",
"amount": 42.23,
"paided": true
}
]
It would the responsibiltity of the server to recognize that now there are more than one invoice to store.
One example of such an API is ElasticSearch bulk update support:
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html
You can take some inspiration there.
Im writing an app for facebook in java.
i have a class named FacebookClient that i got from facebook.
withe this class i can connect to facebook by using
FacebookClient client = new FacebookClient();
client.login(request, response, "api_key", "sec_key");
and get user info with
client.users_getinfo
(For example: client.users_getinfo(String.class, uidJSON, "first_name , last_name , sex , pic_big , pic_small ", "format=json");
the problem is that i need the user profile url and i can't get it!!
does anyone know how to get it (the function or the Query )
Thanks
Check out the Facebook Graph API here
If you make an API call me it will return a large JSON containing various information about you, (or a specified user), and one of the entries is 'link'
Here is a sample call.
https://graph.facebook.com/me?access_token=<the access token>
and the sample return will look like:
{
"id": "01234567",
"name": "Kenny Cason",
"first_name": "Kenny",
"last_name": "Cason",
"link": "http://www.facebook.com/kenny.cason",
"about": "life only comes once",
"birthday": "00/11/2222",
"location": {
"id": "110184922344060",
"name": "Washington, District of Columbia"
},
...
a bunch more info
...
}
You can see the link entry which is a link to my facebook profile. let me know if you need more information.