2017-11-02 1 views
0

내 애플 리케이션에서 내가 트위터를 통해 로그인 한이 세션을 사용 하여이 세션을 사용하여 나는 트위터에 이미지를 게시 할 수 있습니다, 하지만 문제는 다시 시작한 후 이미 내 응용 프로그램에 로그인되어 있습니다 트위터를 통해 있지만 세션을 사용할 수 없습니다. 다시 세션에 들어가려면 로그인해야합니다. 네이티브 트위터 앱이 내 장치에 설치되어 있습니다. 이미 트위터 앱과 내 앱에 이미 트위터를 통해 로그인 한 사용자의 세션을 가져옵니다. 이것을 얻을 수있는 방법이 있습니까?안드로이드에서 트위터에 이미지를 공유

내가 트위터에

public void shareOnTwitter(Bitmap bitmap){ 
     final TwitterSession session = TwitterCore.getInstance().getSessionManager() 
       .getActiveSession(); 
     ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 
     bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes); 
     byte[] byteArray = bytes.toByteArray(); 
     Twitter.getInstance().getTwitterAuthConfig(); 
     if(session != null) { 
      TwitterApiClient twitterApiClient = new TwitterApiClient(session); 

      MediaType mediaType = MediaType.parse("image/*"); 
      RequestBody body = RequestBody.create(mediaType, byteArray); 

      Call<Media> mediaCall = twitterApiClient.getMediaService().upload(body, null, null); 
      mediaCall.enqueue(new Callback<Media>() { 
       @Override 
       public void success(Result<Media> result) { 
        String mediaIdString = result.data.mediaIdString; 

       } 

       @Override 
       public void failure(TwitterException exception) { 
        AppUtil.log("Twitter", "Twitter media failed"); 
       } 
      }); 
     } 
    } 

참고 비트 맵 이미지를 공유하기 위해이 코드를 사용하고 있습니다 : 내가 링크로 의도을 통해 이미지를 공유하지 않으려는

답변

0

당신은 더 성공에서 다음 메소드를 호출 할 필요가 방법 :.

무효 uploadTweetWithMedia (TwitterApiClient 클라이언트, TwitterSession 세션, 문자열 텍스트 문자열 mediaId) { client.getStatusesService() 업데이트 (텍스트, mediaId 사실, NULL, NULL, NULL, NULL, NULL, NULL).enqueue ( 새로운 콜백() { @Override 공공 무효 성공 (결과 결과) { Log.v ("갱신", "성공"+ result.data.idStr); }

     @Override 
         public void failure(TwitterException exception) { 
          Log.v("update", "failure " + exception.getMessage()); 
         } 
        }); 
} 
관련 문제