2015-01-17 3 views
0

실시간 구독을 만들 때 다른 Instagram IP 주소에서 중복 알림을받는 문제가 있습니다. 알림을 받으면 min_tag_id 설정을 사용하여 최신 업데이트에 대한 요청을 보내도록 설정했습니다. 나는 그것을 db에 저장하여 다음 요청에 사용합니다. 필자는 중복을 항상 얻지는 않지만, 알림에 대한 모든 것은 동일한 (time, object, changed_aspect)이며, 두 개의 거의 동일한 요청을 나열하는 디버깅 출력과 다르다는 것을 제외하고는 ... 유일한 것 서로 다른 정보가 다른 IP 주소이고 REQUEST_TIME_FLOAT가 약 1/10 초 차이가 있습니다. 그들은 심지어 같은 HTTP_X_HUB_SIGNATURE 값을가집니다.Instagram 실시간 API 중복 요청

내 일반적인 알고리즘은 다음과 같습니다

process_subscription_update($data){ 
    # get old min_id 
    $min_tag_id = mysqli_fetch_object(mysqli_query($dbconnecti,sprintf("SELECT instagram_min_id+0 as instaid FROM xxxx WHERE xxxx=%d",$_GET['xxxx']))); 
    $min_id = $min_tag_id->instaid; 
    # make api call 
    $ch = curl_init(); 
    curl_setopt($ch,CURLOPT_URL, 'https://api.instagram.com/v1/tags/'.$_GET['tag'].'/media/recent?client_id=xxxx&min_tag_id='.$min_id.($min_id==0?'&count=1':'')); 
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
    $result = curl_exec($ch); 
    curl_close($ch); 
    $i = json_decode($result); 
    if ($min_id == $i->pagination->min_tag_id) { exit; } 
    # write new min_id to db 
    record_min_id($i->pagination->min_tag_id); 
    $data2 = $i->data; 
    foreach($data2 as $d) { 
     process_instagram($d); 
    } 
    // debugging output: **************** 
    $file = file_get_contents($_SERVER['DOCUMENT_ROOT'].'instagram/updates.txt'); 
    $foo = "\n"; 
    foreach($_SERVER as $key_name => $key_value) { 
     $foo .= $key_name . " = " . $key_value . "\n"; 
    } 
    $fulldata = $file . "\n\n\n" . $result . "\n min_id = " . $min_id . $foo; 
    $fulldata .= "\nTIME:".$data[0]->time; 
    $fulldata .= "\nOBJECT:".$data[0]->object; 
    $fulldata .= "\nCHANGED_ASPECT:".$data[0]->changed_aspect; 
    file_put_contents($_SERVER['DOCUMENT_ROOT'].'instagram/updates.txt', $fulldata);  
    // end debugging output ************* 

} 
나는 인스 타 그램 메시지 ID가 이미 process_instagram 함수 내 내 DB에 존재하며 중복에만 두 번째의 1/10을 오는 경우 검사를 피하기 위해 싶습니다

따로, 어쨌든 그것이 효과가 있는지 나는 모른다.

다른 누구나이 경험이 있거나 해결책이 있습니까?

+0

이 문제를 해결하기위한 솔루션을 찾을 수 있었습니까? 나도 똑같은 문제가있다. – user2423476

답변

0

이 문제가 해결되었습니다. 나는 중복 된 통지를받는 것에 대해 할 수있는 일이 없다고 생각합니다. 그래서 Instagram을 db로 작성할 때 Instagram id 필드가 있고 필드에 고유 한 제약 조건을 넣습니다. mysqli INSERT를 수행 한 후, errno = 1062인지 확인하고 만약 그렇다면 종료한다.

mysqli_query($dbconnecti,"INSERT INTO xxx (foo, etc, instagram_id ...") 
if ($dbconnecti->errno==1062) { exit; } 
... 
// more script runs here if we don't have a duplicate.