태그 보관물: twitter

twitter

특정 트윗에 대한 답글, Twitter API 특정 트윗에 대한 응답을받을 수있는 방법이 있습니까?

Twitter API에 특정 트윗에 대한 응답을받을 수있는 방법이 있습니까? 감사



답변

내가 이해하는 바에 따르면 직접 수행 할 수있는 방법은 없습니다 (적어도 지금은 아닙니다). 추가해야 할 것 같습니다. 그들은 최근에 몇 가지 ‘리트 윗’기능을 추가했으며이 기능도 추가하는 것이 논리적으로 보입니다.

이 작업을 수행 할 수있는 한 가지 방법이 있습니다. 첫 번째 샘플 트윗 데이터 (에서 status/show) :

<status>
  <created_at>Tue Apr 07 22:52:51 +0000 2009</created_at>
  <id>1472669360</id>
  <text>At least I can get your humor through tweets. RT @abdur: I don't mean this in a bad way, but genetically speaking your a cul-de-sac.</text>
  <source><a href="http://www.tweetdeck.com/">TweetDeck</a></source>
  <truncated>false</truncated>
  <in_reply_to_status_id></in_reply_to_status_id>
  <in_reply_to_user_id></in_reply_to_user_id>
  <favorited>false</favorited>
  <in_reply_to_screen_name></in_reply_to_screen_name>
  <user>
    <id>1401881</id>
     ...

에서 status/show당신 사용자의 ID를 찾을 수 있습니다. 그런 다음 statuses/mentions_timeline사용자의 상태 목록을 반환합니다. 해당 반환 값을 구문 분석 in_reply_to_status_id하여 원래 트윗의 id.


답변

트윗에 대한 답글을받는 절차는 다음과 같습니다.

  1. 트윗 저장소를 가져올 때 tweetId 즉, id_str
  2. 트위터 검색 API를 사용하여 다음 쿼리를 수행하십시오.
    [q="to:$tweeterusername", sinceId = $tweetId]
  3. 모든 결과를 반복합니다. 일치하는 결과 in_reply_to_status_id_str to $tweetid는 게시물에 대한 답글입니다.


답변

여기 내 해결책이 있습니다. Abraham의 Twitter Oauth PHP 라이브러리를 사용합니다 : https://github.com/abraham/twitteroauth

Twitter 사용자의 screen_name 속성과 해당 트윗의 id_str 속성을 알아야합니다. 이렇게하면 임의 사용자의 트윗에서 임의의 대화 피드를 가져올 수 있습니다.

* 업데이트 : 객체 액세스 대 배열 액세스를 반영하는 새로 고침 된 코드 :

function get_conversation($id_str, $screen_name, $return_type = 'json', $count = 100, $result_type = 'mixed', $include_entities = true) {

     $params = array(
          'q' => 'to:' . $screen_name, // no need to urlencode this!
          'count' => $count,
          'result_type' => $result_type,
          'include_entities' => $include_entities,
          'since_id' => $id_str
     );

     $feed = $connection->get('search/tweets', $params);

     $comments = array();

     for ($index = 0; $index < count($feed->statuses); $index++) {
          if ($feed->statuses[$index]->in_reply_to_status_id_str == $id_str) {
               array_push($comments, $feed->statuses[$index]);
          }
     }

     switch ($return_type) {
     case 'array':
          return $comments;
          break;
     case 'json':
     default:
          return json_encode($comments);
          break;
     }

}


답변

Twitter에는 related_results라는 문서화되지 않은 API가 있습니다. 지정된 트윗 ID에 대한 답변을 제공합니다. 실험적으로 얼마나 신뢰할 수 있는지 확실하지 않지만 이것은 트위터 웹에서 호출되는 것과 동일한 API 호출입니다.

자신의 책임하에 사용하십시오. 🙂

https://api.twitter.com/1/related_results/show/172019363942117377.json?include_entities=1

자세한 내용은 dev.twitter에서이 토론을 확인 하세요 :
https://dev.twitter.com/discussions/293


답변

여기에서는 특정 트윗의 답장을 가져 오는 간단한 R 코드를 공유하고 있습니다.

userName = "SrBachchan"

##fetch tweets from @userName timeline
tweets = userTimeline(userName,n = 1)

## converting tweets list to DataFrame
tweets <- twListToDF(tweets)

## building queryString to fetch retweets
queryString = paste0("to:",userName)

## retrieving tweet ID for which reply is to be fetched
Id = tweets[1,"id"]

## fetching all the reply to userName
rply = searchTwitter(queryString, sinceID = Id)
rply = twListToDF(rply)

## eliminate all the reply other then reply to required tweet Id
rply = rply[!rply$replyToSID > Id,]
rply = rply[!rply$replyToSID < Id,]
rply = rply[complete.cases(rply[,"replyToSID"]),]

## now rply DataFrame contains all the required replies.


답변

쉬운 실용적인 방법이 아닙니다. 이에 대한 기능 요청이 있습니다.

http://code.google.com/p/twitter-api/issues/detail?id=142

API를 제공하는 몇 가지 타사 웹 사이트가 있지만 종종 상태가 누락됩니다.


답변

나는 이것을 다음과 같은 방식으로 구현했습니다.

1) 상태 / 업데이트는 마지막 상태의 ID를 반환합니다 (include_entities가 true 인 경우). 2) 그런 다음 상태 / 멘션을 요청하고 결과를 in_reply_to_status_id로 필터링 할 수 있습니다. 후자는 1 단계의 특정 ID와 동일해야합니다.