ph0817sig / google-spreadsheet-lib-android

Automatically exported from code.google.com/p/google-spreadsheet-lib-android
0 stars 0 forks source link

Problem Uploading Records #12

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I am using gss-lib-2.2, and android 2.3.4. I'm having no problems to create or 
find worksheets but when I try to upload records I get the following problem: 
*Please see attached file: error.png*

This is the code I am using in an IntentService:

protected void onHandleIntent(Intent intent) {
        //try{
            // TODO Auto-generated method stub
            Date date = new Date();
            Calendar calendar;
            WorksheetName = new String(date.getDate() + ", " + date.getMonth() + " ," + (date.getYear()+1900));
            SSFactory = SpreadSheetFactory.getInstance(new AndroidAuthenticator(UpdaterService.this));
            spreadsheets = SSFactory.getAllSpreadSheets();
            SSheet=spreadsheets.get(0);
            worksheets=SSheet.getAllWorkSheets();
            int number = worksheets.size();
            exists=false;
            for(int i=0; i<number; i++){
                if(worksheets.get(i).getTitle().equalsIgnoreCase(WorksheetName)){
                    exists=true;
                    WSheet=worksheets.get(i);
                    Log.i(TAG, "Worksheet Already there");
                    break;
                }
            }
            if(exists==false){
                WSheet=SSheet.addListWorkSheet(WorksheetName,40, ColumnNames);
                //WSheet=SSheet.getWorkSheet(WorksheetName, true).get(0);
                Log.i(TAG, "Created List Worksheet");
            }

            Log.i(TAG, "Got Worksheets");
            /*HashMap<String, String> record2 = new HashMap<String, String>();
            record2.put("Time", "1");
            record2.put("Oxy", "1");
            record2.put("Pulse", "1");

            WSheet.addListRow(record2);*/

            mCursor = dbHelper.getResultsByTime();
            mCursor.moveToNext();
            //mCursor.moveToPosition(position);

            while(mCursor.isAfterLast()==false){
                //***MAKE SURE YOU ADD THE DATA
                record=new Record();
                record.addData("time recorded", mCursor.getString(mCursor.getColumnIndex(C_CREATED_AT)));
                Log.i(TAG, "Time: " + mCursor.getString(mCursor.getColumnIndex(C_CREATED_AT)));
                record.addData("pulse", mCursor.getString(mCursor.getColumnIndex(C_PULSE)));
                Log.i(TAG, "Pulse " + mCursor.getString(mCursor.getColumnIndex(C_PULSE)));
                record.addData("oxygen percentage", mCursor.getString(mCursor.getColumnIndex(C_OXY)));
                Log.i(TAG, "Oxygen Percentage " + mCursor.getString(mCursor.getColumnIndex(C_OXY)));
                WSheet.addListRow(record.getData());
                //Log.i(TAG, getString(mCursor.getPosition()));
                Log.i(TAG, "Added Row");
                mCursor.moveToNext();

                position=mCursor.getPosition();
            }
        //}catch(Exception e){
            //Log.i(TAG, "Internet Problem");
        //}
        mCursor.close();
}

I know that Issue 1 is similar to this, but it is in a different version of the 
gss library. 

Thanks in advance.
George

Original issue reported on code.google.com by gtde...@gmail.com on 23 Aug 2011 at 10:47

GoogleCodeExporter commented 8 years ago
I'm sorry that I left some things in my code that are commented out. Just keep 
that in mind when looking at it.

Thanks,
George

Original comment by gtde...@gmail.com on 23 Aug 2011 at 10:49

GoogleCodeExporter commented 8 years ago
Here is the error. i deleted the other one because it was the wrong picture.

Original comment by gtde...@gmail.com on 23 Aug 2011 at 1:23

Attachments:

GoogleCodeExporter commented 8 years ago
Hi George,

it seems your WorkSheet column names have "space" character. Google SpreadSheet 
Web API which is the backend of this Library doesn't understand space 
character. So please remove space from column name.

Please follow this sample to add/update WorkSheet (ListFeed)-

Add-
HashMap<String, String> row_data = new HashMap<String, String>();
row_data.put("id", "1");
row_data.put("devicename", "Nexus");
row_data.put("vendor", "Google");

// Add entries
WorkSheetRow list_row1 = workSheet.addListRow(row_data);

Update-
row_data.put("id", "2");
row_data.put("devicename", "iPhone");
row_data.put("vendor", "Apple");
workSheet.updateListRow(sp.getEntry().getKey(), list_row2, row_data);

Hope it helps.
Thanks,
Prasanta

Original comment by pprasant...@gmail.com on 24 Aug 2011 at 5:16

GoogleCodeExporter commented 8 years ago
Thank Prasanta.

The first error is now fixed by your help, but now I am getting the following 
error: See attachment*

Here is my current code:

protected void onHandleIntent(Intent intent) {
        //try{
            // TODO Auto-generated method stub
            Date date = new Date();
            Calendar calendar;
            WorksheetName = new String(date.getDate() + ", " + date.getMonth() + " ," + (date.getYear()+1900));
            //SSFactory = SpreadSheetFactory.getInstance(new AndroidAuthenticator(UpdaterService.this));
            SSFactory = SpreadSheetFactory.getInstance("gtdevel@gmail.com", "Starazagora1");
            spreadsheets = SSFactory.getAllSpreadSheets();
            if(spreadsheets==null){
                Log.i(TAG, "problem");
            }
            SSheet=spreadsheets.get(0);
            worksheets=SSheet.getAllWorkSheets();
            int number = worksheets.size();
            exists=false;
            for(int i=0; i<number; i++){
                if(worksheets.get(i).getTitle().equalsIgnoreCase(WorksheetName)){
                    exists=true;
                    WSheet=worksheets.get(i);
                    Log.i(TAG, "Worksheet Already there");
                    break;
                }
            }
            if(exists==false){
                WSheet=SSheet.addListWorkSheet(WorksheetName,40, ColumnNames);
                //WSheet=SSheet.getWorkSheet(WorksheetName, true).get(0);
                Log.i(TAG, "Created List Worksheet");
            }

            Log.i(TAG, "Got Worksheets");
            /*HashMap<String, String> record2 = new HashMap<String, String>();
            record2.put("Time", "1");
            record2.put("Oxy", "1");
            record2.put("Pulse", "1");

            WSheet.addListRow(record2);*/

            mCursor = dbHelper.getResultsByTime();
            mCursor.moveToNext();
            //mCursor.moveToPosition(position);

            while(mCursor.isAfterLast()==false){
                //***MAKE SURE YOU ADD THE DATA
                record=new Record();
                record.addData("TimeRecorded", mCursor.getString(mCursor.getColumnIndex(C_CREATED_AT)));
                Log.i(TAG, "Time: " + mCursor.getString(mCursor.getColumnIndex(C_CREATED_AT)));
                record.addData("Pulse", mCursor.getString(mCursor.getColumnIndex(C_PULSE)));
                Log.i(TAG, "Pulse " + mCursor.getString(mCursor.getColumnIndex(C_PULSE)));
                record.addData("OxygenPercentage", mCursor.getString(mCursor.getColumnIndex(C_OXY)));
                Log.i(TAG, "Oxygen Percentage " + mCursor.getString(mCursor.getColumnIndex(C_OXY)));
                WorkSheetRow list_row1 = WSheet.addListRow(record.getData());
                //Log.i(TAG, getString(mCursor.getPosition()));
                Log.i(TAG, "Added Row");
                mCursor.moveToNext();

                position=mCursor.getPosition();
            }
        //}catch(Exception e){
            //Log.i(TAG, "Internet Problem");
        //}
        mCursor.close();
    }

Do you have any idea what this might be? 

Original comment by gtde...@gmail.com on 24 Aug 2011 at 8:22

Attachments:

GoogleCodeExporter commented 8 years ago
Hey Prasanta, 

I fixed the problem I was having. I had capital letters in my column names but 
the columns ended up being written in all lowercase. Then in my addListRow I 
had the capitalized column names, and that messed it up. Now it works.

Thanks for your help,
George

Original comment by gtde...@gmail.com on 24 Aug 2011 at 5:00

GoogleCodeExporter commented 8 years ago
George,
glad to know that.

May I ask you something, if you could help me to promote-
http://www.mateongo.com

and our facebook page-
http://www.facebook.com/mateongo

within your friend circle.

Thanks,
Prasanta

Original comment by pprasant...@gmail.com on 24 Aug 2011 at 5:05

GoogleCodeExporter commented 8 years ago
Done. Is there an explanation of what mateongo is? It seems interesting.

Original comment by gtde...@gmail.com on 24 Aug 2011 at 5:25

GoogleCodeExporter commented 8 years ago
Thanks George.

It is a patented recommendation engine which helps people to explore 
places/nearby. Helps people to tag places, add review and suggest places within 
their existing friends network, as we trust our friends' suggestion more than 
commercial advertisements.

I would appreciate if you spread this within your circle.

Thanks,
Prasanta

Original comment by pprasant...@gmail.com on 24 Aug 2011 at 5:31

GoogleCodeExporter commented 8 years ago
I will do that. 

Thanks for the help.

George

Original comment by gtde...@gmail.com on 24 Aug 2011 at 6:18

GoogleCodeExporter commented 8 years ago
I would like to see your AndroidAuthenticator() class

I have a similar problem. I can't get spreadsheet when calling 
SSFactory.getSpreadSheets(). My service throw a background thread exception.

I think my AndroidAuthenticator class is the problem.

Paul W

Original comment by paul.wi...@gmail.com on 26 Sep 2011 at 11:26

GoogleCodeExporter commented 8 years ago
I used the manual way of entering authenticate the SSFactory. Either hardcode 
it in, or have a textbox where people can enter it.
I had some problems with the AndroidAuthenticator. I used the one Prasanta had 
in his sample app to begin with, but after a while I began having some errors 
with it and I couldn't figure out why...

George

Original comment by gtde...@gmail.com on 28 Sep 2011 at 12:33

GoogleCodeExporter commented 8 years ago
Thank you for the answer

I also get some errors. I have hardcoded it in too, but the problem is that I 
want to deploy my app to other users...

Paul W

Original comment by paul.wi...@gmail.com on 28 Sep 2011 at 1:14

GoogleCodeExporter commented 8 years ago
Hi Paul & George,

Can you guys pls tell me what exact problem you are having to integrate Android 
Authenticator ? Logs would help me.

alternate to Androidauthenticator is BasicAuthenticator and you need to provide 
Login screen.

Thanks,
Prasanta

Original comment by pprasant...@gmail.com on 28 Sep 2011 at 2:46

GoogleCodeExporter commented 8 years ago
Hi

This is all the information
INFO/System.out(5461): [DEBUG] auth token for wise is null

when calling 
SpreadSheetFactory factory = SpreadSheetFactory.getInstance(account, context); 

and the thread thows an exception
ERROR/AndroidRuntime(5447): FATAL EXCEPTION: AsyncTask #2
09-28 20:15:59.124: ERROR/AndroidRuntime(5447): java.lang.RuntimeException: An 
error occured while executing doInBackground()
09-28 20:15:59.124: ERROR/AndroidRuntime(5447):     at 
android.os.AsyncTask$3.done(AsyncTask.java:200)
09-28 20:15:59.124: ERROR/AndroidRuntime(5447):     at 
java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
09-28 20:15:59.124: ERROR/AndroidRuntime(5447):     at 
java.util.concurrent.FutureTask.setException(FutureTask.java:125)
09-28 20:15:59.124: ERROR/AndroidRuntime(5447):     at 
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
09-28 20:15:59.124: ERROR/AndroidRuntime(5447):     at 
java.util.concurrent.FutureTask.run(FutureTask.java:138)
09-28 20:15:59.124: ERROR/AndroidRuntime(5447):     at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
09-28 20:15:59.124: ERROR/AndroidRuntime(5447):     at 
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
09-28 20:15:59.124: ERROR/AndroidRuntime(5447):     at 
java.lang.Thread.run(Thread.java:1027)
09-28 20:15:59.124: ERROR/AndroidRuntime(5447): Caused by: 
java.lang.ClassCastException: com.pawi.stryktipswidget.StryktipsService
09-28 20:15:59.124: ERROR/AndroidRuntime(5447):     at 
com.pras.SpreadSheetFactory$LoginTask.doInBackground(SpreadSheetFactory.java:528
)
09-28 20:15:59.124: ERROR/AndroidRuntime(5447):     at 
com.pras.SpreadSheetFactory$LoginTask.doInBackground(SpreadSheetFactory.java:1)
09-28 20:15:59.124: ERROR/AndroidRuntime(5447):     at 
android.os.AsyncTask$2.call(AsyncTask.java:185)
09-28 20:15:59.124: ERROR/AndroidRuntime(5447):     at 
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
09-28 20:15:59.124: ERROR/AndroidRuntime(5447):     ... 4 more

Original comment by paul.wi...@gmail.com on 28 Sep 2011 at 6:24

GoogleCodeExporter commented 8 years ago
It seems to work with
AccountManagerFuture<Bundle> amf = accountManager.getAuthToken(account, 
params[0], null, null, null, null);

instead of
AccountManagerFuture<Bundle> amf = accountManager.getAuthToken(account, 
params[0], null, (Activity) context, null, null);

last in the SpreadSheetFactory file class LoginTask

I do need to do more tests to be sure!

Paul W

Original comment by paul.wi...@gmail.com on 28 Sep 2011 at 9:34