6

I am writing a chrome extension and I want to use Curl to get me the download links of the gmail attachments. How should i do it? I am new to curl and i don't know how would i able to use the curl library in javascript ?

2
  • I am fairly certain I can help you further than the currently accepted answer, but your question is not very clear. Do you want to get the URL values of links (e.g. by scraping the user's messages), or do you actually want to download the data of the attachment to the hard drive? Commented Aug 7, 2012 at 15:00
  • no .. i don't want to download the data .. suppose you email me an attachment, for eg: images.zip .. now what i want is the link of the "download button" coz when the link is extracted it appears to be like .. "mail.google.com/mail/u/0/h/mc707syj8bjk/…" but i want the redirected exact link which may be like .. "mail.google.com/mail/u/0/images.zip" .. I hope its clear now Commented Aug 8, 2012 at 4:10

2 Answers 2

6

You can't use cURL directly in Javascript. You can do AJAX though. So one solution would be to setup a php script somewhere that you can use for getting links from gmail.

EDIT: There is an implementation of cURL in javascript here. Check it out.

Sign up to request clarification or add additional context in comments.

5 Comments

can ajax help me with getting the download links with javascript ?
I think it is quite difficult. Because, you'd naturally be doing something that requires cookies to work. cURL can support cookies. But, AJAX can't. It's purely for fetching/sending data.
Ajax absolutely supports cookies -- an Ajax request is just like a regular request for a Web page, but it is initiated by JavaScript. All Ajax requests are sent with the same cookies as would be sent if you typed the destination URL into your address bar. However, cross-domain Ajax may require a withCredentials property, but I don't think that is even necessary if your are performing a cross-domain request as a Chrome extension with domain permissions.
@goldenparrot Why do you suggest a PHP script? With the appropriate permissions, Chrome extensions can fetch cross-domain resources just fine, and a PHP script will not fetch the resources with the appropriate session cookie. A PHP script that attempts to get the user's inbox will likely end up fetching the Gmail login page, because it doesn't have access to the user's Gmail cookies. A Chrome extension with *://mail.google.com/* permissions will fire Ajax requests that fetch the inbox as the logged-in users sees it.
I suggested php because I thought curl has powerful cookie handling functionality through cookiejar, cookiefile. And, another thing is since php is widely used, there would be scripts to do mostly everything one needs.
1

Just as a reference same origin policy in javascript. While there appears to workarounds this, security is always going to be a concern.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.