Twitter API -> updating profile bg image with php

后端 未结 4 1151
故里飘歌
故里飘歌 2021-01-01 07:03

So far I have been trying to update the twitter profile bg image thr the twitter api with php... and without success

Many examples on the web, including this one:

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-01 07:46

    This is what works for me (debug stuff left in):

    $url      = 'http://twitter.com/account/update_profile_background_image.xml';
    $uname    = 'myuname';
    $pword    = 'mypword';
    $img_path = '/path/to/myimage.jpg';
    $userpwd  = $uname . ':' . $pword;
    $img_post = array('image' => '@' . $img_path . ';type=image/jpeg',
                      'tile'  => 'true');
    
    $opts = array(CURLOPT_URL => $url,
                  CURLOPT_FOLLOWLOCATION => true,
                  CURLOPT_RETURNTRANSFER => true,
                  CURLOPT_HEADER => true,
                  CURLOPT_POST => true,
                  CURLOPT_POSTFIELDS => $img_post,
                  CURLOPT_HTTPAUTH => CURLAUTH_ANY,
                  CURLOPT_USERPWD => $userpwd,
                  CURLOPT_HTTPHEADER => array('Expect:'),
                  CURLINFO_HEADER_OUT => true);
    
    $ch = curl_init();
    curl_setopt_array($ch, $opts);
    $response = curl_exec($ch);
    $err      = curl_error($ch);
    $info     = curl_getinfo($ch);
    curl_close($ch);
    
    echo '
    ';
    echo $err . '
    '; echo '----------------' . '
    '; print_r($info); echo '----------------' . '
    '; echo htmlspecialchars($response) . '
    '; echo '
    ';

提交回复
热议问题