I am making a app using google Fact Check API and and the response json is like this
{
"claims": [
{
"text": "“President El-Sisi confirmed Egypt's unwavering strategic position on Libya, which aimed at restoring stability in the country, preserving its national institutions, and preventing further deterioration in Libya’s security situation via curbing illegal foreign interference in the Libyan issue.”",
"claimant": "Abdel-Fattah al-Sisi",
"claimDate": "2020-07-24T00:00:00Z",
"claimReview": [
{
"publisher": {
"name": "POLYGRAPH.info",
"site": "polygraph.info"
},
"url": "https://www.polygraph.info/a/egypt-libya-sisi-intervention/30745850.html",
"title": "Egypt's al-Sisi Told Trump Foreign Interference in Libya is Bad – Just as his Parliament Authorized him to Intervene",
"reviewDate": "2020-07-24T00:00:00Z",
"textualRating": "Misleading",
"languageCode": "en"
}
]
}
],
"nextPageToken": "CAE"
}
I want to know how can i get the urls image and display it like this
image
I can't seem to figure out how to get the image as in the JSON there is only url of the webpage.
Edit:-
Here is the code in which i am using GSON to store the values
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.i("response",response.toString());
Search search = gson.fromJson(response.toString(),Search.class);
Log.i("response",search.toString());
textView.setText("Claim:- "+search.claims.get(0).text+"\nFactual Rating:-"+search.claims.get(0).claimReview.get(0).textualRating);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.i("response",error.toString());// TODO: Handle error
}
});
If you know the exact website you can use a web scraper. Look how you can do it here.
Related
User can get image from camera and gallery aslo user can crop image and setting in view working good.but after that i want to update it's profile with it's other data like "Name" ,"Number" etc.
by postman image is uploading successfully.
I tried multipart, way sending as file and also try to send as a string but not getting successful or Failure response.i don't know what I m doing wrong. I m new in android please help if you can.
Response and Get Structure
{
"id": 7,
"profile_image": " ImageUrl will come here",
"firstname": "Hamza",
"lastname": "Ali",
"email": "hamzaregardless333#gmail.com",
"contact": "123455666",
"gender": "Male",
"location": "lahore"
}
I don't know where you made a mistake because you didn't share your code.
I'm uploading image like below. Maybe it can help you.
Your Service
public interface YourService {
#Multipart
#POST("api/exampleImageUpload")
Call<YourResponse> uploadImage(
#Part MultipartBody.Part image
);
}
Uploading Image
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://backendapi.com/")
.build();
File file = new File(imagePath);
MultipartBody.Part filePart = MultipartBody.Part.createFormData("paramName","imageName",RequestBody.create(MediaType.parse("multipart/form-data"), file));
YourService iys = retrofit.create(YourService.class);
Call<YourResponse> uploadCall = iys.uploadImage(filePart);
uploadCall.enqueue(new Callback<YourResponse>() {
#Override
public void onResponse(Call<YourResponse> call, Response<YourResponse> response) {
}
#Override
public void onFailure(Call<YourResponse> call, Throwable t) {
}
});
I'm new to JSON handling with retrofit but I've run into a problem.
We're making a prototype smart assistant chatbot with Dialogflow.
My Android Client sends a POST request to Google Dialogflow, which will call third party API's and send a response back.
However, this response depends on the type of intent detected by Dialogflow.
It can be nearly everything from music to weather information etc.
So the parameters (for the visualization) will be completely different and I don't know the type of response in advance.
I preprocess the response from Dialogflow in my own cloud function and send it back containing only the necessary fields for the client.
For example:
"What is the weather today in Brussels?"
Response:
{
"sessionId": "123456789",
"keepAlive": true,
"intentId": 100,
"intentName": "Weer",
"text": "Het weer in Hanoi is helder met een temperatuur van 23.2 graden.",
"Parameters": {
"text": {
"stringValue": "helder",
"kind": "stringValue"
},
"city": {
"stringValue": "Hanoi",
"kind": "stringValue"
},
"temp": {
"numberValue": 23.2,
"kind": "numberValue"
},
"intentId": {
"numberValue": 100,
"kind": "numberValue"
}
}
}
You can see the Parameters of the response depend on the type of intent(id). there can be many or zero parameters depending on the intent.
How can I make a Pojo for every type of response, not only the weather?
Or can I make a switch case based on intentId or something?
You can use generics than
public class Response<T> {
private String responseId;
private String sessionId;
private boolean keepAlive;
private float intentId;
private String intentName;
private String text;
private String Audio;
private T Parameters;
}
and when you want to create the object you can
new Response<YourClass>();
Your class will be the class as per your intent id
I am developing a navigation application which uses Google Maps. I am trying to implement "my nearby user location" with the application.
I want to use the Algolia service for searching geo-locations using GeoFire with Android & Firebase.
I have successfully stored latitude and longitude information in my Algolia index with their documentation's guidance.
But I don't understand how I can automatically fetch the list and map the location (like in sample project of algolia instant search) based on my current location without entering the place name or any address. Here's my current code:
com.algolia.search.saas.Query query = new com.algolia.search.saas.Query().setAroundLatLng(new com.algolia.search.saas.Query.LatLng(lat,lng)).setAroundRadius(5000);
index.searchAsync(query, new CompletionHandler() {
#Override
public void requestCompleted(JSONObject jsonObject, AlgoliaException e) {
}
});
What's the problem you are facing? Are you blocked on what to do next? The jsonObject you get in requestCompleted is going to be something like:
{
"hits": [
{
"firstname": "Jimmie",
"lastname": "Barninger",
"objectID": "433",
"_highlightResult": {
"firstname": {
"value": "<em>Jimmie</em>",
"matchLevel": "partial"
},
"lastname": {
"value": "Barninger",
"matchLevel": "none"
},
"company": {
"value": "California <em>Paint</em> & Wlpaper Str",
"matchLevel": "partial"
}
}
}
],
"page": 0,
"nbHits": 1,
"nbPages": 1,
"hitsPerPage": 20,
"processingTimeMS": 1,
"query": "jimmie paint"
}
In Java you can access it like jsonObject.getObject("hits").
Are you using instantsearch-android or algoliasearch-client-android ? You should use the instantsearch-android one, is easier to link the search with your UI. Here's an example with GoogleMaps.
I'm requesting my me/albums with:
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/albums",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
parseAlbumResponse(response);
}
}).executeAsync();
Problem is that the response object only contains 3 fields:
{
"data": [
{
"created_time": "...",
"name": "...",
"id": "..."
},
...
Instead of all fields documented here. Sames goes for /{album-id}/photos:
{
"data": [
{
"created_time": "...",
"id": "..."
},
...
Instead of this.
It was working last time I've checked but all of a sudden this strange behaviour happened.
I've tested with Facebook Graph API and the result it's the same so I guess it's not a problem from my app.
I'm using 'com.facebook.android:facebook-android-sdk:4.7.0'.
Did Facebook changed something in the requests parameters?
EDIT:
As user luschn suggested:
Declarative Fields
To try to improve performance on mobile networks, Nodes and Edges in
v2.4 requires that you explicitly request the field(s) you need for
your GET requests. For example, GET /v2.4/me/feed no longer includes
likes and comments by default, but GET
/v2.4/me/feed?fields=comments,likes will return the data. For more
details see the docs on how to request specific fields.
So I had to change my requests to:
Web console:
me/albums?fields=name, cover_photo, count and /{album-id}/photos?fields=id, images
Java:
Bundle parameters = new Bundle();
parameters.putString("fields", "id, images");
Bundle parameters = new Bundle();
parameters.putString("fields", "name, cover_photo, count");
https://developers.facebook.com/docs/apps/changelog#v2_4
Search for "Declarative Fields" in the changelog, you have to specify the fields you want to get returned.
I would like to integrate Facebook's comment social plugin
( https://developers.facebook.com/docs/reference/plugins/comments/ to comment on url) into my android application.
I tried to use webview (use this answer Android unable to implement facebook comment in a webview due to default browser ) and it's work, but hard to customize, for example: I want to have a bigger Textbox for user to type the comment. My question is: "is there any solution to integrate something like "Facebook's comment social plugin" into android application by facebook sdk, java code,... to comment on url?
Thanks & best regards
As far as I understand you have some URL page where you've embedded your facebook social plugin with comments and you want to parse this and display as you want. If I'm right, then unfortunately I haven't found easy solution via triggering appropriated methods from Facebook SDK. You have to use Graph API.
First of all we need to take a look into docs - https://developers.facebook.com/docs/graph-api/reference/v2.3/object/comments
Here there is a example of call
/* make the API call */
new Request(
session,
"/{object-id}/comments",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
For getting {object_id} you need to send similar call to the Graph API, but for retrieving id:
GET-> ?id=http%3A%2F%2Fwww.imdb.com%2Ftitle%2Ftt2015381%2F
And you will receive response which looks like
{
"og_object": {
"id": "10150298925420108",
"description": "Directed by James Gunn. With Chris Pratt, Vin Diesel, Bradley Cooper, Zoe Saldana. A group of intergalactic criminals are forced to work together to stop a fanatical warrior from taking control of the universe.",
"title": "Guardians of the Galaxy (2014)",
"type": "video.movie",
"updated_time": "2015-05-15T14:52:46+0000",
"url": "http://www.imdb.com/title/tt2015381/"
},
"share": {
"comment_count": 4,
"share_count": 91073
},
"id": "http://www.imdb.com/title/tt2015381/"
}
10150298925420108 is our object_id
So next query looks like GET -> 10150298925420108/comments
and response
{
"data": [
{
"id": "10150298925420108_10152457293990108",
"can_remove": false,
"created_time": "2014-10-28T18:12:15+0000",
"from": {
"id": "1513986108857171",
"name": "ซอโซ่ สระอา ยอยัก"
},
"like_count": 2,
"message": "สนุกมากค่ะ",
"user_likes": false
},
{
"id": "10150298925420108_10152457392770108",
"can_remove": false,
"created_time": "2014-10-28T19:20:28+0000",
"from": {
"id": "302917246580502",
"name": "สมชาย โกทันธ์"
},
"like_count": 0,
"message": "สองดาวครับ\n",
"user_likes": false
},
{
"id": "10150298925420108_10152461977130108",
"can_remove": false,
"created_time": "2014-10-31T11:57:10+0000",
"from": {
"id": "472810482857795",
"name": "Surat Thaenphet"
},
"like_count": 0,
"message": "แต่ละเรื่องที่ลง สนุกมาก แต่ดูไม่จบ ดูสักพัก ก็ eror ไม่รุ้เป็นเพราะอะไร",
"user_likes": false
}
],
"paging": {
"cursors": {
"before": "Mw==",
"after": "MQ=="
}
}
}
To test all this requests and response before doing it in Android app - use Graph API explorer https://developers.facebook.com/tools/explorer/