com.google.gdata.util.InvalidEntryException when max-results is in URL - pagination

I want to change max-results while retrieving comments of a video from youtube. This is my code :
YouTubeService service = new YouTubeService(
"CLIENT_ID");
String str="http://gdata.youtube.com/feeds/api/videos/"+videoId;
YouTubeQuery youtubeQuery = new YouTubeQuery(new URL(
str));
youtubeQuery.setMaxResults(50);
youtubeQuery.setStartIndex(1);
String videoEntryUrl = youtubeQuery.getUrl().toString();
System.out.println(videoEntryUrl+" *************");
VideoEntry videoEntry = service.getEntry(new URL(videoEntryUrl),
VideoEntry.class);
While creating VideoEntry object in the last row, it gives this error :
Exception in thread "main" com.google.gdata.util.InvalidEntryException: The 'max-results' parameter is not supported on this resource
http://schemas.google.com/g/2005'>GDataunsupportedQueryParamThe 'max-results' parameter is not supported on this resource
My code prints the query so when it gives error query is like that :
http://gdata.youtube.com/feeds/api/videos/v_wzBsZLLaE?start-index=1&max-results=40
Why max-results parameter is not supported in this situation?
Greetings

You are requesting video information about one video. So, for 1 video, using start-index and max-results does not make any sense. (If it would be allowed then both can only be 1.)

Related

Error "Failed to construct URI for OData request with request path" SAP Java VDM withQueryParameter

I have create a CAP VDM in java with SAP SDK 3.29.1.
In event handler #On read, i would like to pass the input filters to the VDM.
Es.
#On(event = CdsService.EVENT_READ, entity = "XXXX")
public void readXXX(CdsReadEventContext context) throws ODataException {
final String filter = context.getParameterInfo().getQueryParameter("$filter");
final List<XXXXX> dati = new DefaultXXXService().getAllXXXX().select().withQueryParameter("$filter", filter).executeRequest(dest);
}
When run the query in the log i get the error:
"Failed to construct URI for OData request with request path ..."
"Illegal character in query at index 95. ...."
But the path and filter is right for the call, can you help me?
In the old version sdk i used:
FilterExpression filtriFrontEnd =FilterExpressionConverter.convertTo(queryRequest.getQueryExpression());
final List<XXXX> area = new DefaultXXXXService().getAllXXX().filter(new UncheckedFilterExpression<>(filtriFrontEnd)).select().execute(new ErpConfigContext("XXX"));
Thank you.
When run the query in the log i get the error: "Failed to construct URI for OData request with request path ..." "Illegal character in query at index 95. ...."
Can you check whether the following works for you..?
import com.sap.cloud.sdk.datamodel.odata.client.request.ODataUriFactory;
final String filter = context.getParameterInfo().getQueryParameter("$filter");
final String encodedFilter = ODataUriFactory.encodeQuery(filter);
final List<XXXXX> dati = new DefaultXXXService().getAllXXXX().select().withQueryParameter("$filter", encodedFilter ).executeRequest(dest);
Please let me know, as this could be an issue that needs to be addressed.
The method contract of withQueryParameter which explicitly warns about this API usage:
Using this function to bypass fluent helper method calls can lead to unsupported response handling. There is no contract on the order or priority of parameters added to the query.
Instead please use the filter function directly. There should be an entity field for the postal code, the code should look similar to this:
new DefaultXXXService()
.getAllXXXX()
.filter(Entity.POSTAL_CODE.eq("16100"))
If this is not feasible in your use case I suggest to build this filter expression manually as you did before and apply encoding to it as Alex pointed out in his answer.

How to remove characters after a semicolon as I can't use split()

I have the following code, which is returning the following information but I only need the name of the clinic and not the rest of the information. How would I remove them?
Intent secondIntent = getIntent();
final String message = secondIntent.getStringExtra("Add a Review for");
This is producing the following information: Ringwood Family Medical Centre : Shop 19A/59-65 :8842 6200 : 3134
but I only need the name of the clinic and I tried using the following code but there is some kind of error:
message = message.split(":", Integer.parseInt("10"));
Actually, I think String#split might be want you want here:
final String message = secondIntent.getStringExtra("Add a Review for")
.split("\\s*:\\s*")[0];

Getting value of key from Web Content Display Portlet

I got a requirement. I have added two text fields Value and Key from structure in Web Content Display portlet.
right now in the portlet i am getting value from hard code like below.
BasicModel model = (BasicModel)requestContext.getFlowScope().get("BasicModel");
if(model == null){
model = new BasicModel();
}
model.setEmployeeId("AB1223344S");
model.setHireDate("01-Jan-2000");
model.setNiNumber("AB123456S");
model.setDateOfBirth("12-Dec-1980");
model.setBasicForm(new BasicDetailsForm());
}
but what i want is to get the value of each attribute from web content. Like, If i have given lfr.intel.empid as key and ABSD1822D as value in the added web content structure field like this.
and we can fetch the value of key like this.
model.setEmployeeId(lfr.intel.empid);
You can write a custom function for this which passes the key to that function, now that function will use the JournalArticleLocalServiceUtil API to get respective value from the DB.
Now you need to find How to fetch values from JournalArticleLocalServiceUtil, which you can google or this link can help you.
Thanks.
Try this, assuming that you could get the JournalArticle object, I've done it using the resourcePrimKey
long resourcePrimKey = 12345; //hard coded the resourcePrimKey
JournalArticle article = JournalArticleLocalServiceUtil.getLatestArticle(resourcePrimKey);
com.liferay.portal.kernel.xml.Document document = SAXReaderUtil.read(article.getContentByLocale("en_US"));
Node keyNode = document.selectSingleNode("/root/dynamic-element[#name='Key']/dynamic-content");
String key = keyNode.getStringValue();
Node valueNode = document.selectSingleNode("/root/dynamic-element[#name='Value']/dynamic-content");
String value = valueNode .getStringValue();

Parse attribute of Media Element

I want to parse url attribute from the XML and show image in image control (the one reffered to by the URL) in listbox from the following feed link: http://feeds.bbci.co.uk/news/rss.xml
My code is:
var ComingNewsFromUri = from rss in XElement.Parse(e.Result).Descendants("item")
select new NewsItems
{
Title = rss.Element("title").Value,
PubDate = rss.Element("pubDate").Value,
Description = rss.Element("description").Value
};
For RSS, I would recommend using SyndicationFeed and SyndicationItem....does all the parsing and converting to objects automatically and brilliantly for you.
http://ryanhayes.net/blog/how-to-build-an-rss-feed-reader-in-windows-phone-7part-i-retrieving-parsing-and-displaying-post-titles/
I have an RSS feed app on the store myself using SyndicationFeed and it is very reliable and convenient.
Here is another sample by Microsoft
http://code.msdn.microsoft.com/wpapps/RSS-Reader-Sample-1702775f

Flickr api doesn't return the estimated value

I am using flickr api in order to count the how many times a tag occur. I want this information in order to calculate the Normalized Google Distance. I am using this query in my java code:
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&tags=bank
But i don't get good results. For example when i search "bank" the count value is 357439, when i search "credit" the count value is 59288, but when i am search for "bank credit" the count value is only 2. When i searching with the search box at flickr.com for "bank credit" i get a lot of results. But as far as i can see the query it uses is
http://www.flickr.com/search/?q=bank%20credit
which i am not able to use through my java code. I am trying to pass this
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&q=bank
and it says
Parameterless searches have been disabled. Please use flickr.photos.getRecent instead
How can i solve this problem?
Your generated url is incorrect
http://api.flickr.com/services/rest/method=flickr.photos.search&api_key=XXXXXXX&format=json&q=bank
is missing the question mark
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&q=bank
UPDATE based on OP comments:
I didn't see you had the question mark on the top url string. Looking at it again, I did realize you are not passing in any valid parameters. "q" isn't one of the listed parameters on the search api page. Try something like below to search photos with "bank" tag
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&tags=bank
or one with bank in description/title
http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=XXXXXXX&format=json&text=bank
I got the same error. but when I added media = photos in the parameters, it got resolved.
e.g. :
baseurl = "https://api.flickr.com/services/rest/"
params_d['api_key'] = 'XXXXXXX'
params_d['method'] = 'flickr.photos.search'
params_d['tag'] = "river,mountains"
params_d['tag_mode'] = 'all'
params_d['per_page'] = 5
params_d['media'] = "photos"
params_d['nojsoncallback'] = 1
params_d['format'] = 'json'
resp = requests.get(baseurl, params = params_d)

Resources