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);
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
I am not able to post data to server. On clicking button i submit form and i am getting data into api service class but it's not sending to server which place somewhere else. I am going to give all detail here under:I have other apis method in service class they are working well , but when i want to post data, i am not able to post data and neither getting any response from server while checking database no entry there:
service.ts : orgId is string which is pass in url as foreign key to add adresspostmodel , and data is json object. I am using data:any(reason the actual table has more field which auto generated). when i use postman the api and all working well with same url and json object as i giving hereunder:
service.ts :
public postFormData(orgId: string, data: any): Observable<AdressModel> {
return this.http.post<any>(`${this.ApiUrl}/${orgId}/addresses`, data).pipe(
tap(response => console.log(response)), catchError(this.handleError));
}
onSubmit(){
this.data =
{
"city": "test",
"email": "test#gemiil.com",
"name": "test2",
"recipient": "test",
"street": "test",
"zipCode": "12345"
}
this.ApiService.postFormData(this.organizationId, this.data);
}
this.data actually i am getting data from form, but here form example i am giving you json mock object, which is also correct, here is my json object and whole api in console both api , och json object in console is looking correct for me :
api data in console
{
"city":"test",
"email":"test#gemiil.com",
"name":"test2",
"recipient":"test",
"street":"test",
"zipCode":"12345"
}
Can anyone help to find what's problem is there with logic?
Observable are lazy in nature, so you must subscribe to make it to send request to server.
this.ApiService.postFormData(this.organizationId, this.data).subscribe((resp) => console.log(resp));
When using the Java Google Play Developer API (version 3), and requesting purchase information for a valid purchase token, I get the below exception. The API call returns a 400 Bad Request response with the following message.
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid Value",
"reason" : "invalid"
} ],
"message" : "Invalid Value"
}
Unfortunately there is no further information. I do not know what value is invalid.
First, we have contacted Google support about this. Unfortunately we have been going back and forth with Google support for almost 2 months and they still haven't even indicated they correctly understand what our problem is. Every time they reply, they give us suggestions that have literally nothing to do with the Google Play Developer API, even after thoroughly explaining the problem multiple times. This is the most frustrating support experience I've had in 20 years. Google support is clearly not going to be of any help here.
Second, we have successfully linked our Google Play account and our back-end. All necessary configuration is complete and working. On our back-end we are getting notifications from Google Play whenever an Android in-app purchase is made, and these notifications include a purchase token. This took some substantial effort, but I am confident this is now all correct, our service account is configured correctly, and all permissions and such are good.
I am able to successfully call the API that returns a list of available in-app-purchase products. I get a full and correct listing of the products we have configured in Google Play for users to purchase in our app. In order to make this call, we must provide credentials, and I assume the server is validating these credentials when we make this call. Since I can successfully make this call, I am assuming the "Invalid Value" is not related to our credentials. We are using a Google-generated JSON file created for a specific service account (not using a p12 file).
I have searched StackOverflow, and the rest of the internet looking for information on this issue. I have found many pages indicating the same or similar problem, but using an older version of the Google Play Developer API, which apparently did things differently. The solutions offered do not seem to apply to the v3 API. I have been searching for many weeks and trying various solutions I've come across all with no success.
I have written a test app that I run on my local PC which works when I am requesting a listing of in-app products, but does not work when requesting the purchase details for a given purchase token. I have tried with many different purchase tokens. I read that the test tokens are not actually valid for use with this particular API, so I actually released to production a build of our app that I am able to make a real, actual purchase with. I have done this, been charged by Google, and our back-end has received real and valid purchase tokens from these purchases.
private static void testGooglePlayDevAPI_Purchase() throws Throwable {
final String productIdSku = "[the_product_sku]";
final String purchaseToken = "[a_valid_purchase_token]";
final String packageName = "[our_app_id]";
final File GOOGLE_PLAY_DEV_API_CREDENTIALS =
new File("path_to_file/google-api-credentials.json");
final FileInputStream credentials =
new FileInputStream(GOOGLE_PLAY_DEV_API_CREDENTIALS);
final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
final HttpTransport TRANSPORT =
GoogleNetHttpTransport.newTrustedTransport();
String scope = AndroidPublisherScopes.ANDROIDPUBLISHER;
GoogleCredential credential = GoogleCredential
.fromStream(credentials, TRANSPORT, JSON_FACTORY)
.createScoped(Arrays.asList(scope));
AndroidPublisher publisher = new AndroidPublisher
.Builder(TRANSPORT, JSON_FACTORY, credential)
.setApplicationName(packageName)
.build();
try {
AndroidPublisher.Purchases purchases = publisher.purchases();
AndroidPublisher.Purchases.Products products = purchases.products();
AndroidPublisher.Purchases.Products.Get get =
products.get(packageName, productIdSku, purchaseToken);
ProductPurchase product = get.execute();
System.out.println(String.format(
"Product purchase data found [developerPayload=%s]",
product.getDeveloperPayload()));
} catch (Throwable t) {
System.out.println(ExceptionSupport.getExceptionDetails(t));
}
}
I expect the above code to give me a response with valid product purchase data (a valid ProductPurchase instance that I can interrogate and process). Instead, all I ever get here is a 400 Bad Request response indicating that SOME VALUE (I don't know which) is invalid. The actual response is:
com.google.api.client.googleapis.json.GoogleJsonResponseException:
400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid Value",
"reason" : "invalid"
} ],
"message" : "Invalid Value"
}
UPDATE:
I've provided my own answer to this question below.
I'll provide my own answer here because we finally found a work-around. It turns out that something in the Java Google Play Developer API (v3) client library is not working correctly. I don't know what it is, but the documentation for that client library is terrible and Google provides NO examples of using it. However, it turns out that we can successfully use the HTTPS/JSON/OAuth2 API directly without going through the Java client. We have implemented our server-side solution using this approach and caching the OAuth2 tokens in memcache until they expire.
I double-checked and we were emailing back-and-forth with Google support for 2 months!!! They were of no assistance at all. I find this to be remarkable (in a bad way).
I am trying to integrate twitter feeds in my website. I want each tweet obtained from a user as a seperate json object so tat i can customise the look and feel of each object.
Can anyone help me with this ?
I have generated the OAUTH token.How do i use it in my code? I dont want to use PHP. Is there any other way using java or javascript?
I am using this link to access my twitter feeds:
https://api.twitter.com/1.1/search/tweets.json?q=bindyareddy&since_id=24012619984051000&max_id=250126199840518145&result_type=mixed&count=4
I am getting JSON response like :
{
"errors": [
{
"message": "Bad Authentication data",
"code": 215
}
]
}
I am trying to get location co-ordinates based on WiFi access point details using Google GeoLocation API. The issue is I am always returned the same co-ordinate for every request.
The URL to which I am passing my JSON request is: https://www.googleapis.com/geolocation/v1/geolocate?key=MY_API
The JSON data that I am passing is:
{
"radioType":"wcdma",
"homeMobileNetworkCode":"0",
"homeMobileCountryCode":"234",
"carrier":"BT",
"wifiAccessPoints":
{
"signalStrength":-73,
"age":0,
"macAddress":"BSSID HERE",
"channel":6
}
}
I am UK based, which is why I have set MNC to 234. Also, I can only use wifi for location services as there is no GPS installed in the current configuration.
The response that I always receive from Google is:
{
"location":
{
"lat": 51.517098999999995,
"lng": -0.146084
},
"accuracy": 18000.0
}
I receive that response for all my requests, irrespective of any BSSID that I pass as request. Could you tell me what am I doing wrong here? I am passing this data as a POST request using Java (using the standard HTTP Connection listed here)
If you take a look at the Google Geolocation API Documentation:
https://developers.google.com/maps/documentation/business/geolocation/#cell_tower_object
You can see the 'cellTowers' and 'wifiAccessPoints' sections are setup to use JSON Arrays.
So, to fix your example, it should look like this:
{
"radioType":"wcdma",
"homeMobileNetworkCode":"0",
"homeMobileCountryCode":"234",
"carrier":"BT",
"wifiAccessPoints":
[{
"signalStrength":-73,
"age":0,
"macAddress":"BSSID HERE",
"channel":6
}]
}