2011-08-08 4 views
0

트위터를 업데이트하려고 Twitter4J (2.1.0)를 사용하고 있습니다. 내 코드가 무엇이 잘못되었는지 알 수 없다. 특히Twitter 4J를 사용하여 트윗을 업데이트하는 방법은 무엇입니까?

내 문제는 다음과 같습니다

의 (a) 모든 트윗이 성공적으로 게시 할 수 있습니다. 나는 종종 -1의 에러 코드를 얻는다. 구글 그룹 post ...

에 따르면 당신은 코드를 얻을 -1 내부 HTTP 구성 요소가 에 연결하거나 API에서 읽을 실패 할 때. 또한 DNS 관련 문제로 인해 API가 에 JVM에서 연결할 수없는 경우 코드 -1이 표시 될 수 있습니다.

나는 이상하게도 매 2 초마다이 게시물을 받고있는 것처럼 보였다. 이 오류를 처리 할 때마다 -1 오류 코드를 받으면 다시 업데이트하려고합니다. 나는 이것이 아주 좋은 해결책이 아니라는 것을 알지만. 이것은 probem에게 새로운 트윗이 오래된 트윗을 일치 할 때마다 시간

(B) 나는 중복 에러가 발생 (에러 코드 403)의 95 %를 고정

오류 코드 (403)에도 중복 된 경우 발생 이제 구식이되어 ...

내 현재 코드 (예. "안녕하세요"를 다시 오류 코드 (403)와 TwitterException을 던졌습니다 게시 한 후, 상태 업데이트의 다양한 게시, "안녕하세요"POST)

내 코드가 활동이 아닌 서비스에서 차례로 사용되는 AsyncTask에 있습니다. 나는 트위터 API 이미했습니다 트윗 일치하는 모든 트윗을 거부합니다

class SendTwitAsyncTask extends AsyncTask<String, Void, Void> { 

    @Override 
    protected Void doInBackground(String... params) { 
     String tokenTwit = params[0]; 
     String tokenSecretTwit = params[1]; 
     String strMessageBody = params[2]; 

     AccessToken aToken = new AccessToken(tokenTwit, tokenSecretTwit); 

     // initialize Twitter4J 
     Twitter twitter = new TwitterFactory().getInstance(); 
      twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); 
      twitter.setOAuthAccessToken(aToken); 


     // create a tweet 
     // strMessageBody varies 
     String tweet = strMessageBody; 




     boolean bool = twitter.isOAuthEnabled(); 

     if (twitter.isOAuthEnabled()) { 
      GeoLocation geolocation = new GeoLocation(-33.91, 151.25); 
      try { 

       twitter.updateStatus(tweet, geolocation); 
       showNotification("Twitter One" , TWIT_SUCCESS); 

      } catch (TwitterException te) { 

       if (te.getStatusCode() == -1) { 
        //try again 
        try { 
         twitter.updateStatus(tweet, geolocation); 

         showNotification("Twitter Two ", TWIT_SUCCESS); 
        } 
        catch (TwitterException tetwo) { 
         describeTwitException(tetwo.getStatusCode()); 
        }  
       } //end if 

       //else exception other than -1 
       else { 
        describeTwitException(te.getStatusCode()); 
       } //end else 

      }// end outer catch 
     } //end if 
     else { 
      showNotification("Unable to authenticate" , TWIT_FAIL); 
     }// 
     return null; 
    } 



} //end class SendTwitAsyncTask 

public void describeTwitException(int twitExceptionCode) { 
    switch (twitExceptionCode) { 

    case (-1): 
     showNotification("Twitter (unable to connect)", TWIT_FAIL); 
     break; 
    case(403): 
     showNotification("Twitter (duplicate tweet)", TWIT_FAIL); 
     break; 
    default: 
     showNotification("Twitter", TWIT_FAIL); 

    } //end switch 
} //end describeTwitException method 

답변

1

AsyncTask를 코드 아래에 다른 방법을 .... 포함했다. 나는 옛날 트윗이 '만료 된 것'이라고 생각하지 않는다.

+0

답변 해 주셔서 감사합니다. 트위터의 안드로이드 앱에서 중복 트윗을 보냈습니다. 최근 타임 라인에 중복 트윗을 보내지는 못합니다. 그러나 원래 트윗이 아주 오래되었을 때 (예 : 1 년 이상) 중복 트윗이 성공적으로 게시됩니다. 추신. 질문에 답을 남겼으나 -1 개의 오류 코드 상태가 표시되는 이유를 여전히 확실하지 않습니다. – Mel

관련 문제