sooshin / android-news-app

News App Project as a part of Android Basics Nanodegree at Udacity. Navigation Drawer | ViewPager plus TabLayout | Loaders | JSON Parsing | SharedPreferences
MIT License
150 stars 102 forks source link

How to Add Other News Site #1

Closed deshanonline closed 5 years ago

deshanonline commented 5 years ago

How to Add Other News Site

sooshin commented 5 years ago

This app fetches data from the Internet with the Guardian API, so it only displays Guardian news.

Kshitizkhadka commented 5 years ago

how can i add the costom newa on this app

sooshin commented 5 years ago

There's no feature that you can add custom news

esQmo commented 5 years ago

Can I use it to display news from a respective news web site? The site generates data in JSON format what can be modified from your app to achieve this?

sooshin commented 5 years ago

I'm sorry, but you cannot use this app to display news from a respective news web site. When I was building this app, I learned how to make an app that connects to the Internet in the Udacity course. The main idea of the code about Networking belongs to Udacity. The UI design is my idea though. The purpose of this repository is to help other Udacians, classmates of Udacity.

chakrapanibrahmam commented 5 years ago

Can you share me Guardian business URL, as i am getting confuse NewsPreferences.java class.

sooshin commented 5 years ago

Here it is. https://content.guardianapis.com/search?q=&order-by=newest&page-size=10&order-date=published&from-date=2010-01-01&show-fields=thumbnail,trailText&format=json&show-tags=contributor&api-key=test&section=business

The base URL is "https://content.guardianapis.com/search" and then append query parameters using .appendQueryParameter.

You don't need to use all that query parameters that I used, but show-tags=contributor shows author name and show-fields=thumnail shows the images.

order-by, page-size, order-date, from-date are query parameters for preferences.

You may want to take a look at the requests and responses from the Guardian API: https://open-platform.theguardian.com/explore/

chakrapanibrahmam commented 5 years ago

Hi, Here is the URL: https://newsapi.org/v2/top-headlines?country=in&category=business&apiKey=7ff1a4bf6f8541a8b8036d79a959a426 which i want to build. Well i am unable to append the URL with the same method which you used. please help me to clear this.

sooshin commented 5 years ago

Hi, Uri baseUri = Uri.parse("https://newsapi.org/v2/top-headlines"); Uri.Builder uriBuilder = baseUri.buildUpon(); uriBuilder.appendQueryParameter("country", "in") uriBuilder.appendQueryParameter("category", "business"); uriBuilder.appendQueryParameter("apiKey", "7ff1a4bf6f8541a8b8036d79a959a426");

String url = uriBuilder.toString();

Let me know how it goes.

chakrapanibrahmam commented 5 years ago

Hi, Please check as in my case apikey comes at the end of the URL and category='business' comes before the apikey, where i am unable to return Category (uriBuilder.appendQueryParameter(SECTION_PARAM, section).toString();) in getPreferrelUrl method and call that in Fragment.java NewsPreferences.getPreferredUrl(getcontext(),getString(R.string.bussiness));.

Well i am trying to create separate fragment for each category like

  1. Business 2.Sports 3.health
  2. Entertainment etc.

Guardian

https://content.guardianapis.com/search?q=&order-by=newest&page-size=10&order-date=published& from-date=2010-01-01&show-fields=thumbnail,trailText&format=json&show-tags=contributor&api-key=test&section=business

Newsapi

https://newsapi.org/v2/top-headlines?country=in&category=business&apiKey=7ff1a4bf6f8541a8b8036d79a959a426

Please find the url and help me to solve the issue.

sooshin commented 5 years ago

Hi, Did you replace SECTION_PARAM with "category"? Could you please share your code snippet?