I need to read the content of some posts i'm retrieving from a blogger feed.
This code retrieves the first available post from the blogger feed
URL postsFeedUrl = new URL("http://www.blogger.com/feeds/" + blogId + "/posts/default");
Query postsQuery = new Query(postsFeedUrl);
Feed resultFeed = myService.getFeed(postsQuery, Feed.class);
Entry e = resultFeed.getEntries().get(i);
The problem is: how to get the post content?
If i use
e.getContent();
i get a Content object from which i don't know how to extract the real post content.
If i use
e.getPlainTextContent();
It results in
Exception in thread "main" java.lang.IllegalStateException: TextConstruct object is not a PlainTextConstruct
at com.google.gdata.data.BaseEntry.getPlainTextContent(BaseEntry.java:358)
at BloggerFeed.printAllPosts(BloggerFeed.java:49)
at BloggerFeed.main(BloggerFeed.java:28)
How can i retrieve the post content with the GData API?
You need to add param fetchBodies=true.
Related
I am able to get access token for google contact API. Now I am not able to figure out how to use that token to fetch contacts. The method available in Google Contact API documentation does not involve access token. Also I don't know how to call that method in Java.
If Anyone can help me with that, it will be highly appreciable.
ContactsService service = new ContactsService("Test");
service.setHeader("Authorization", "Bearer " + access_token);
URL feedUrl = new URL("google.com/m8/feeds/contacts/default/full");
ContactFeed resultFeed = service.getFeed(feedUrl, ContactFeed.class);
System.out.println(resultFeed.getTitle().getPlainText());
This is how I am trying to fetch contacts but I am getting:
com.google.gdata.util.ParseException: Feature: xml.org/sax/features/external-general-entities
I am new to azure iot. and i am trying to create shared access policies in azure iot hub using its rest api.
https://management.azure.com/subscriptions/{subscription-Id}/resourceGroups/{group-name}/providers/Microsoft.Devices/IotHubs/{hub-name}?api-version=2016-02-03");
and my java code is
String policyold = "{\"tags\" : {}, \"location\": \"East Asia\",\"properties\" : \"authorizationPolicies\" : [{\"name\" : \"policy-namw\", \"primaryKey\" : \"{mykey}\" ,\"secondaryKey\" : \"secondary-key\" ,\"permissions\" :[\"ServiceConnect\" ,\"RegistryRead\" ,\"RegistryWrite\" ,\"DeviceConnect\"]}],\"eventHubEndpoints\" : { \"events\" : {\"messageRetentionInDays\":\"2\"}}}";
StringEntity input1 = new StringEntity(policyold);
input1.setContentType("application/json");
input1.setContentEncoding("UTF8");
put.setEntity(input1);
put.setHeader("Authorization", token);
HttpResponse r2 = httpclient2.execute(put);
System.out.println(r2.getStatusLine());
String content2 = EntityUtils.toString(r2.getEntity());
org.json.JSONObject recvObj2 = new org.json.JSONObject(content2);
but i am facing the followiing error.
HTTP/1.1 400 Bad Request {"error":{"code":"InvalidRequestContent","message":"The request content was invalid and could not be deserialized: 'Error converting value \"authorizationPolicies\" to type 'System.Collections.Generic.Dictionary`2[System.String,Newtonsoft.Json.Linq.JToken]'. Path 'properties', line 1, position 76.'."}}
Moreover i am using this tutorial.https://msdn.microsoft.com/en-us/library/mt589015.aspx
Can any one help me in solving this?
According to the offical document Common error codes for Azure IoTHub, the error code 400 means "The body of the request is not valid; for example, it cannot be parsed, or the object cannot be validated.".
I checked the policyold string value in your code, then I found the json string missed the required elements Sku name & Units. Please carefully see the table of the elements below the end of the Json request content.
An Azure IoTHub can own multiple shared access policies.
So if creating shared access policy while creating new IoTHub, please use the REST API Create a new IoT Hub, else use the REST API Update metadata on an existing IoT Hub to add a new one for an existing IoTHub.
I'm trying to use Yahoo Content Analysis using a file containing text as input. So every character and length is possible.
This code works with a simple text String (no special characters, short text) however when I use longer texts or special characters I get a Bad Request error (HTTP 400) sometimes with an error message like "no viable alternative at character '['" or without an error message.
I encode every request and HTTP Post shouldn't have any limit as to the length.
Does the Yahoo service place a limit on the length of the request and/or are there any characters that it can't handle?
Any help to help this work is appreciated!
Here's my code (using commons-httpclient):
String fileInput = FileUtils.readFileToString(f);
StringBuilder builder = new StringBuilder();
builder.append("http://query.yahooapis.com/v1/public/yql?");
System.out.println(fileInput);
builder.append("q=")
.append(URLEncoder.encode("select * from contentanalysis.analyze where text='"+ fileInput +"'" , "UTF-8"))
.append("&format=json");
final String postUrl = builder.toString();
HttpClient client = new HttpClient();
PostMethod method = new PostMethod(postUrl);
// Send POST request
int statusCode = client.executeMethod(method);
I think the problem is that while you are sending the request as an HTTP POST, the YQL query and text are all included in the URL. YQL does not really have a way for you to make HTTP POST requests directly, so I can think of a couple options:
Directly use the Content Analysis web service with an HTTP POST (docs)
Create a custom YQL data table which uses the <execute> tag to run custom JavaScript which could do the POST (example)
Of these options I think the former would be easier.
My code is: (sensitive info removed)
SpreadsheetService service = new SpreadsheetService("MySpreadsheetIntegration-v1");
// service.setUserCredentials(<email>, <pw>);
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
oauthParameters.setOAuthConsumerKey("xxx.yyy.no");
oauthParameters.setOAuthConsumerSecret("XXX");
oauthParameters.setOAuthToken("YYYY");
oauthParameters.setOAuthTokenSecret("ZZZZ");
oauthParameters.setScope("https://docs.google.com/feeds/ https://docs.googleusercontent.com/ https://spreadsheets.google.com/feeds/");
service.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
// Define the URL to request. This should never change.
URL SPREADSHEET_FEED_URL = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
// Make a request to the API and get all spreadsheets.
SpreadsheetFeed feed = service.getFeed(SPREADSHEET_FEED_URL, SpreadsheetFeed.class);
List<SpreadsheetEntry> spreadsheets = feed.getEntries();
// Iterate through all of the spreadsheets returned
for (SpreadsheetEntry spreadsheet : spreadsheets) {
// Print the title of this spreadsheet to the screen
System.out.println(spreadsheet.getTitle().getPlainText());
}
Issue:
WARNING: Authentication error: Unable to respond to any of these challenges: {authsub=WWW-Authenticate: AuthSub realm="https://www.google.com/accounts//AuthSubRequest"}
and
com.google.gdata.util.AuthenticationException: Token invalid - AuthSub token has wrong scope
I tried clientLogin method (setUserCredentials(, )) and that works fine.
I also know my OAuthConsumerKey, OAuthConsumerSecret, OAuthToken and OAuthTokenSecret work, cos I access a different feed using them (picasa)
I have tried setting different combinations of the above 3 scopes, but no luck.
I have seen this and this, but again, no luck.
Any help would be greatly appreciated.
Take a look at this answer.
Try to delete the following directory:
$HOME/.credentials
After what run the program again, it's gonna make a callback and ask you to grant permissions for your application in Google Console and now it's gonna work properly.
I'm writing an application using the public Tumblr API, just for fun. I have set up my oauth keys, and I have the URL for accessing my blog's info. I was wondering how I could take the JSON-encoded data from that page and turn it into Strings for working with.
To be clear, if I wanted a blog's title, I could send a request to this URL and select the data for the title.
Thanks!
I've used Restlet for retrieving JSON data from a rest service. Below is the sample
Representation entity = new ClientResource("your url").get();
JsonRepresentation jsonRepresentation = new JsonRepresentation(entity.getText());
JSONObject jsonObject = jsonRepresentation.getJsonObject();