Find profile url in Facebook - java

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.

Related

Java - Google Drive API v3 - return specific fields for file - syntax

I am trying to get a large junk of Drive Files. I need to get the 3 Parameters emailAdress, displayName and modifiedTime. I only want to call the API once, to reduce processing time. However I cant figure out the syntax for the combined fields.
files = getDriveService().files().list()
.setFields("files, permissions(emailAddress,displayName)")
.setIncludeTeamDriveItems(true)
.setSupportsTeamDrives(true).execute();
Gives me:
"code": 400,
"errors": [
{
"domain": "global",
"location": "fields",
"locationType": "parameter",
"message": "Invalid field selection permissions",
"reason": "invalidParameter"
}
],
"message": "Invalid field selection permissions"
I`ve tried:
.setFields("files, permissions(emailAddress,displayName)")
.setFields("files(modifiedTime), permissions(emailAddress,displayName)")
.setFields("files/modifiedTime, permissions(emailAddress,displayName)")
.setFields("modifiedTime, permissions(emailAddress,displayName)")
.setFields("permissions(emailAddress,displayName)")
.setFields("modifiedTime")
Is it even possible to setFields() in combination with
.setSupportTeamDrives(true)
Thanks for your help.
A Permission refers to who can access a file. It is connected to a specific file.
Because of this, permissions is a field of the File resource, not a field in Files.list response, so it's normal that you're not getting the desired outcome. So you should access permissions as a field inside files. The request should be like this:
.setFields("files(modifiedTime, permissions(emailAddress, displayName))")
I hope this is of any help.

User profile JSON data from SAP CP CF environment

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.

How to get the attachment ID in JIRA

I want to delete the attachments in JIRA using REST service in JAVA.
restTemplate.delete("http://issusteackingsomething/jira/rest/api/2/attachment/{id})
I need to have the attachment ID from JIRA for the attachment to be deleted.
How do i get that attachment ID?
Use:
https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-getIssue
This is simple URL-requst. Use URL:
http://"Your_domain_jira"/rest/api/2/issue/"Issue ID or Issue Key"
Parse responce json and you find all information about attachments, like that:
"attachment":[{"self":"what ever link", "id":"some sort of id that you need"} ]
You have to know issue key in order to understand to which issue attachment belongs. It can be done in DB or using rest api call:
http://issusteackingsomething/jira/rest/api/latest/issue/ISSUEKEY
In case of REST API call you will have to parse output:
"attachment": [
{
"self":
"id": "1074703",
"filename": "",
"author": {

Extraction reactions data from facebook via restFb java api?

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);

Facebook Opinion Mining using Java

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?

Categories