Saturday, 11 January 2014

Google drive integration with java web application

Google drive setting:-

1.) Open the link ---> https://developers.google.com/drive/?hl=en

2.) At the left hand side you will see a Quickstart  menu , click on quickstart

3.) Click on JavaScript under QuickStart menu

4.) You will be directed to the link ---> https://developers.google.com/drive/quickstart-js

5.) Go to Step 1:and click on link ** Google APIs Console ** and you will be directed to the console page

6.) Click on the dropdown on the left hand side of the page name API Project

7.) Here you will see the option of create project .

8.) Click on create project and give any name in the project and save

9.) Select the Services tab in your API project, and enable the Drive API and Drive SDK.

10.) Select the API Access tab in your API project, and click Create an OAuth 2.0 client ID.

11.)In the Branding Information section, provide a name for your application (e.g. "Google Drive"), and click Next. Providing a product logo is optional.

12.) In the Client ID Settings section, do the following:

    a.) Select Web application for the Application type.

    b.) Click the more options link next to the heading, Your site or hostname.

    c.) List your hostname in the Authorized Redirect URIs and JavaScript origins fields. 

    d.) In the first text field (hostname in the Authorized Redirect) enter --->https://example.com/networking/Service

    e.) In the second text field JavaScript origins enter--->https://example.com

    f.) Click Create Client ID.

    g.) Note down the Client ID you will need it later

13.) In the API Access page, locate the section Client ID for Web applications and note the Client ID value.

14.) Now go to Drive SDK on the console page .

15.) Go to icons and provide a icon(Application icon)

16.) Go to Drive Integration section

17.) In the Open URL(Required)provide a URL EG:https://example.com/networking/Service

18.) Note down the App ID on the top of the page you will need it later


 Integration with  your web application :-

1)Code for google drive in jsp page.

2) Enter your generated client-id in code

3) Enter the App-Id in code

4) Enter the File-id in code

5)Now run your code.

Jsp code-

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Picker </title>

  
    <!-- The standard Google Loader script. -->
    <script src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">

    // Use the Google Loader script to load the google.picker script.
    google.setOnLoadCallback(createPicker);
    google.load('picker', '1');

    // Create and render a Picker object for searching images
    // and uploading files.
    var fileId;
    var aa;
    function createPicker() {
        // Create a view to search images.
        var view = new google.picker.View(google.picker.ViewId.DOCS);
        view.setMimeTypes('image/png,image/jpeg,file/pdf');

        // Use DocsUploadView to upload documents to Google Drive.
        var uploadView = new google.picker.DocsUploadView();

        var picker = new google.picker.PickerBuilder().
            addView(view).
            addView(uploadView).
            setAppId(917725371450).
            setCallback(pickerCallback).
            build();
        picker.setVisible(true);
    }

    // A simple callback implementation.
    function pickerCallback(data) {
        if (data.action == google.picker.Action.PICKED) {
             fileId = data.docs[0].id;
          
            alert('The user selected: ' + fileId);
          
          
        
        }
    }
    function getValue()
{
    aa = window.fileId;
    alert(aa); // yup, it's "test"
}

    </script>
     <script type="text/javascript" src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
   <script type="text/javascript" src="https://apis.google.com/js/api.js"></script>
    <script type="text/javascript">
   init = function() {
        // aa = window.fileId;
        //  alert(aa);
        s = new gapi.drive.share.ShareClient('917725371450');
        s.setItemIds("0B-J5z2jag-KZSjhIeEFpQWdnQ2M");
     
    }
    window.onload = function() {
     
        gapi.load('drive-share', init);
    }
  

 </script>
  </head>
  <body>
      <button onclick="getValue()">Show</button>
     <button onclick="s.showSettingsDialog()" >Share</button>
    
  </body>
</html>

Output of created application -

 when we run application window open as,


upload your document like images, pdf etc,






view your uploaded document


And now we can share document which we uploaded.
So we can use this with our any web application in which we want to provide google drive functionality and share our documents with others.



Packages Installation on Debian Squeeze


Steps for Java Installation on Debian :-

Open terminal-
# java –version
 
Check java version if java is not installed in your machine error will be shown as-
The program 'java' can be found in the following packages:
 * gij-4.3
 * java-gcj-compat-headless
 * openjdk-6-jre-headless
 * cacao
 * gij-4.2
 * jamvm
 * kaffe
 
Edit /etc/apt/sources.list
deb http://ftp2.de.debian.org/debian squeeze main non-free
 
Update-
# apt-get update
 
Check for available java package-
# apt-cache search sun-java6
 
Install java-
# apt-get install sun-java6-jdk
 


MySQL installation on Debian Sqeeze :-
Open source list-
/etc/apt/sources.list

Add into source list-
# Main dotdeb repository
deb http://packages.dotdeb.org squeeze all
deb-src http://packages.dotdeb.org squeeze all

Go to terminal-
# Install the GnuPG key
cat dotdeb.gpg | sudo apt-key add -

apt-get update

Installing MySql-5.5
apt-get install mysql-5.5 mysql-server-5.5

mysqladmin -u root password yourpassword

"yourpassword what you want to set password for mysql 
like root, admin, abc, 123 etc...."

mysql -u root -p

Press enter after this command.

Enter password:
Enter your password here.
Now your mysql ready to use.




Tomcat Installation on Debian Squeeze:-

Open source list-
/etc/apt/sources.list

Add into source list-
#tomcat
deb http://rodolphe.quiedeville.org/debian/ squeeze-backports main
 
Go to terminal-
Update apt keyring-
gpg --export $(gpg --keyserver hkp://pgp.mit.edu --recv-keys 72F1F20D) | apt-key add -
apt-get update
apt-get install tomcat7 tomcat7-admin 
 
Update the file-
/etc/tomcat7/tomcat-users.xml
 
<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>
 
Now you tomcat is ready to use.
 
Connect to your tomcat server-
http://<server name>:8080/
 
 Phpmyadmin Installation steps-

Open-
/etc/apt/sources.list

Add into source list-
deb http://packages.dotdeb.org squeeze-php54 all
deb-src http://packages.dotdeb.org squeeze-php54 all

Open terminal-
apt-get install -t squeeze-php54 php5 php5-mysql
apt-get install -t squeeze-php54 php5 php5-mysql php5-imagick php5-json

/etc/init.d/apache2 restart

Open browser-
http://localhost/phpmyadmin/

Now your phpmyadmin is ready to use.

Netbeans Inatallation steps-

Download netbeans from-
http://www.oracle.com/technetwork/java/javase/downloads/jdk-7-netbeans-download-432126.htmlYour downloaded file such as-
netbeans-7.4-linux.sh

Open terminal-chmod +x jdk-7u25-nb-7_3_1-linux-i586.sh

Start netbeans installer-./jdk-7u25-nb-7_3_1-linux-i586.sh

Follow all steps of installer one by one and finish. 

Now your netbeans is ready to use.


Some useful commands for Linux-

Commands for retrieving and sending data into server or local IP using SCP-

Send data to server-
#scp file.txt user@domain.com:/home/dir1/subdir1/


Retrive data from server-
#scp user@domain.com:/home/user/file.txt file.txt