From Google app script (https://developers.google.com/apps-script/),I got this:-
var doc = DocumentApp.create('Hello, World');
// Access the body of the document, then add a paragraph.
doc.getBody().appendParagraph('This document was created by Google Apps Script.');
// Get the URL of the document.
var url = doc.getUrl();
What I would like to do is to be able to duplicate this from my javascript or java code so I can create a doc and get its URL. Any help is appreciated.
You'll need to use the Google Drive API.
Related
As per the html the source code is:
{result.data}
While requesting the URL result.data is set with 100 and am able to see the value as 100 in the browser. Where as while I am trying to execute the java program with the same url request I am unable to see the value as I have seen in browser.
URL url = new URL(site)
url.openConnection() etc..
I wanted to get the same content as I have seen in the browser through java program.
Your question is not very descriptive, but I guess you are trying to scrape data from the site.
You can use the following libraries for this task:
Jaunt (http://jaunt-api.com)
Jsoup (http://jsoup.org/cookbook/extracting-data/dom-navigation)
HTMLUnit
To what i understand, you want to do one of the below things :
Instead of reading the result line by line, you want to parse it as an XML to as to traverse to div(s) and other html tags.
For this purpose i would suggest you to use jsoup library.
When you hit the URL: www.abcd.com/number=500 in browser, it loads an empty div and on load it fetches data from somewhere, this data which it fetches on load, you want to fetch this using java ?
For this, there must be some js in the resulting page, which is fetching data by hitting some service on page load, you will need to look up in the page to know the service details and instead of hitting this URL (www.abcd.com/number=500) you will need to hit that service to get data.
According to the things I've found twitter4J seems to be the most prominent tool when it comes to Java and Twitter. I went through the code examples and javadoc but I couldn't find a way to do this.
What I want to do is, extract the tweet (content of the tweet) using the URL of it. I tried using JSOUP and the CSS selector but when its a conversation it pulls all the tweets of it. How can I do it using Twitter4J?
Input tweet URL -> Output the content of the tweet
Using jsoup is easier, u can do this:
Document doc = Jsoup.connect("the tweet url here").timeout(10*1000).get();
Element tweet = doc.select(".js-tweet-text-container").first();
now u can use the tweet object to parse the information.
I was trying to extract some tweets from mobile.twitter.com in an android, and as a result I get a mixed html document. After some searches I realized that I need to set an user agent.
My aim is to set a default user agent which would work not only for me, but also for other users who would use my application.
Document doc = Jsoup.connect("https://mobile.twitter.com/").userAgent(...).get();
For those who might be interested there is an easy way for getting default user agent if you are on Android 2.1 or above.
There is a system property called http.agent, which can be used to retrieve the User-Agent string.
My code would then turn to:
String userAgent = System.getProperty("http.agent");
Document doc = Jsoup.connect("https://mobile.twitter.com/").userAgent(userAgent).get();
I have a document (native Google doc) in Google Drive that I need to update from my Java app. What I did so far is to download the doc as html
String downloadUrl = doc.getExportLinks().get("text/html");
HttpResponse resp = service.getRequestFactory()
.buildGetRequest(new GenericUrl(downloadUrl))
.execute();
String contents = IOUtils.toString(resp.getContent());
Then I update the contents in the String object and send the update to Drive:
ByteArrayContent mediaContent = ByteArrayContent.fromString("text/html", contents);
service.files().update(doc.getId(), doc, mediaContent).execute();
This works fine for very simple documents. But if the document contains an image, it disappears. The src attribute of the img tag is empty.
Does Google provide some other methods of updating the contents of a Google Document? Is there an API similar to the Google Spreadsheet API?
Unfortunately Google doesn't provide a fine-grained REST API for manipulating the contents of a Google Docs document. Google Apps Script provides a service that does this, but it may be difficult to integrate it into your Java application.
I am writing Google Docs to my local app document downloader.
In Google Docs API page:
http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#DownloadingDrawings
They say that:
Important: We highly recommend using the link provided by an entry's content link and not constructing this URL manually.
I have explored all Entry attributes, but I really can't find the appropriate link attribute. Can someone help?
MediaContent mc = (MediaContent) entry.getContent();
String UrlForDownload = mc.getUri();
Thats it!
tada!