-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I am not able to fetch the data from the api #7
Comments
Me too |
hey bro
hey bro I have 3 steps to solve this query
|
Hi,
I am getting Volley Error Occured . Please can you help me with it. I have
added the Header function already. I have mentioned the Code below.
val queue = Volley.newRequestQueue (activity as Context)
val url = "https://newsapi.org/v2/top-headlines?country=in&apiKey=97027177615d46768cc3d8701f41cbff"
if(InternetConnectionManager().checkConnectivity(activity as Context)){
val jsonObjectRequest = object :
JsonObjectRequest(Request.Method.GET, url, null, Response.Listener {
try {
progressLayout.visibility = View.GONE
val success = it.getBoolean("success")
if (success){
val data = it.getJSONArray("data")
for (i in 0 until data.length()){
val newsJsonObject = data.getJSONObject(i)
val newsObject = news(
newsJsonObject.getString("title"),
newsJsonObject.getString("authur"),
newsJsonObject.getString("description"),
newsJsonObject.getString("url"),
newsJsonObject.getString("urlToImage")
)
newsInfoList.add(newsObject)
recyclerAdapter =
NewsDashboardRecyclerAdapter(activity as Context, newsInfoList)
recyclerNewsDashboard.adapter = recyclerAdapter
recyclerNewsDashboard.layoutManager = layoutManager
}
} else {
Toast.makeText(activity as Context, "Some Error Has
occured!!", Toast.LENGTH_SHORT).show()
}
} catch (e: JSONException){
Toast.makeText(activity as Context, "Some unexpected error
occurred!!", Toast.LENGTH_LONG).show()
}
}, Response.ErrorListener {
Toast.makeText(activity as Context, "Volley Error
occurred!!!", Toast.LENGTH_LONG).show()
}){
override fun getHeaders(): MutableMap<String, String> {
val headers = HashMap<String, String>()
headers["Content-type"] = "application/json"
headers["token"] = "97027177615d46768cc3d8701f41cbff"
return headers
return super.getHeaders()
}
}
queue.add(jsonObjectRequest)
…On Wed, Jun 23, 2021 at 4:27 PM sumit619sharma ***@***.***> wrote:
hey bro
I am not able to fetch the data from the api. I am getting compelete blank
screen after adding volley request in News app. Please can you help me as I
have to submit Newapp as assignment very soon.
hey bro I have 3 steps to solve this query
1. Add this Header function
<https://stackoverflow.com/questions/64585493/unexpected-response-code-403-while-fetching-data-from-apis>
2. Make JsonObjectRequest of type (object : )
3. if your MainClass is abstract remove the abstract (Keyword)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#7 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKPKZBTU3MSDI3ARBDOGNITTUG425ANCNFSM4674JGWQ>
.
|
@SurajVC27 use retrofit instead of volley |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am not able to fetch the data from the api. I am getting compelete blank screen after adding volley request in News app. Please can you help me as I have to submit Newapp as assignment very soon.
The text was updated successfully, but these errors were encountered: