jbarwick / linkedin-j

Automatically exported from code.google.com/p/linkedin-j
0 stars 0 forks source link

com.google.code.linkedinapi.client.LinkedInApiClientException: java.io.IOException: Stream is closed #79

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I am trying to get my linkedin friends list. Its load successfully, but when 
again i am trying to sync my friend list it gives me Stream is Closed error .

Here i posted my code.

    private String consumerKey = "e3ppgdhog29k";
    private String consumerSecret = "AKZWCuPzOrL2U2dM";
    private String CALLBACKURL = "biztek://mainactivity";
    private LinkedInOAuthService oAuthService;
    private LinkedInApiClientFactory factory;
    public  LinkedInRequestToken liToken;
    public  LinkedInAccessToken liAccessToken;
    private LinkedInApiClient client;

private void initLinkin() 
    {
        try 
        {
            oAuthService = LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(consumerKey, consumerSecret);
            factory = LinkedInApiClientFactory.newInstance(consumerKey, consumerSecret);
            liToken = oAuthService.getOAuthRequestToken(CALLBACKURL);

            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken.getAuthorizationUrl())).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_FROM_BACKGROUND);
            startActivity(intent);
        } 
        catch (Exception e) 
        {
           e.printStack();  
        }
    }

protected void onNewIntent(Intent intent) 
    {
        super.onNewIntent(intent);
        Uri uri = intent.getData();
        if (uri != null && uri.toString().startsWith(CALLBACKURL)) 
        {
             try 
             {  
                    db = new Database(getApplicationContext());
                    db.OpenDatabase();
                    db.deleteLinkedInTable();
                    db.closeDatabase();

                    String verifier = intent.getData().getQueryParameter("oauth_verifier");
                    LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(liToken, verifier);
                    client = factory.createLinkedInApiClient(accessToken);
                    Connections con = client.getConnectionsForCurrentUser();
                    List<Person> lp = con.getPersonList();
                    @SuppressWarnings("unused")
                    String str[] = new String[lp.size()];

                    myDB = openOrCreateDatabase(Database.DATABASE_NAME,SQLiteDatabase.OPEN_READWRITE, null);
                    myVals = new ContentValues();
                    myDB.beginTransaction();

                    for(int i=0;i<lp.size();i++)
                    {
                        Person p = lp.get(i);
                        try
                        {
                            String temp_fname = p.getFirstName();
                            myVals.put("lk_fname",temp_fname);

                            String temp_lname = p.getLastName();
                            myVals.put("lk_lname",temp_lname);

                            String temp_location = null;
                            if(p.getLocation() != null)
                                temp_location = p.getLocation().getName();
                            else
                                temp_location = "";
                            myVals.put("lk_location",temp_location);

                            String temp_url=null;
                            if(p.getPictureUrl() != null)
                                 temp_url=p.getPictureUrl();
                            else
                                 temp_url= " ";
                            myVals.put("lk_url",temp_url);

                            String temp_id = p.getId();
                            myVals.put("lk_id",temp_id);
                            myDB.insert(LINKEDIN_TABLE, null, myVals);
                        }
                        catch (Exception e) 
                        {
                            e.printStackTrace();
                        }
                    }

                    myDB.setTransactionSuccessful();
                    myDB.endTransaction();
                    myDB.close();

                    readDataFromLinkedin() ;
             }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
    }

Again when i call initLinkin() function from my sync function it gives me error.

can anyone tell me what is the erro ?

Any help is appreciated.

Original issue reported on code.google.com by chirag.r...@gmail.com on 10 Nov 2011 at 10:24

GoogleCodeExporter commented 9 years ago
I have a same problem, did anyone solved this issue?

Original comment by syedfara...@gmail.com on 17 Jan 2013 at 11:51

GoogleCodeExporter commented 9 years ago
I too have this problem. any updated solution? is this thread active?

and i have added question in other forums also,

http://stackoverflow.com/questions/14396800/cannot-able-to-get-public-profile-ur
l-from-linkedin-in-android-bufferedinputstr

No answers.

Original comment by farg...@gmail.com on 23 Jan 2013 at 2:33