douzhenqun1271 2011-08-18 03:33
浏览 47
已采纳

从输出中获取推文ID?

I am posting a tweet with a picture, and I am trying to get the ID from it. I have asked it before, but for some reason it's not working anymore? Here is my code:

require 'tmhOAuth.php';
require 'tmhUtilities.php';

$tmhOAuth = new tmhOAuth(array(
    'consumer_key' => '****',
    'consumer_secret' => '****',
    'user_token' => '****',
    'user_secret' => '****',
)); 

$image = "./../images/image.png";

$code = $tmhOAuth->request('POST', 'https://upload.twitter.com/1/statuses/update_with_media.json',
array(
    'media[]'  => "@{$image}",
    'status'   => "Don't slip up" 
),
true,
true 
);

print_r($tmhOAuth);

$tweet_id = $tmhOAuth->id_str;

echo "<br><br><br> Try this: $tweet_id";

I get a whole bunch of text from the print_r, but $tweet_id is blank? I know it's in there. Here's part of the output:

"id_str":"104032165678944257"

Here's the full response:

tmhOAuth Object ( [params] => Array ( ) [headers] => Array ( [Authorization] => OAuth oauth_consumer_key="nY4E8qXJVxICLYTs9R2BLQ", oauth_nonce="dfac47eb37ca8897cf2542123d1638f9", oauth_signature="lHjemKp%2BJVmVgD3cQ9ady4Qb66o%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1313638299", oauth_token="129314956-PJCTyRqrhoTr5IyLGkma9CjDbss5Uohtml2qMmll", oauth_version="1.0" [Expect] => ) [auto_fixed_time] => [buffer] => [config] => Array ( [consumer_key] => nY4E8qXJVxICLYTs9R2BLQ [consumer_secret] => 64UGkGOcwqAKSLieXHOVBFgkXFJujYFkhzYTd1Yjls [user_token] => 129314956-PJCTyRqrhoTr5IyLGkma9CjDbss5Uohtml2qMmll [user_secret] => udoKo0bRmNcKY9WIHEi8cWDMldPS5PyGYEgrYWRcWPk [use_ssl] => 1 [host] => upload.twitter.com [debug] => [force_nonce] => [nonce] => dfac47eb37ca8897cf2542123d1638f9 [force_timestamp] => [timestamp] => 1313638299 [oauth_version] => 1.0 [curl_connecttimeout] => 30 [curl_timeout] => 10 [curl_ssl_verifypeer] => [curl_followlocation] => [curl_proxy] => [curl_proxyuserpwd] => [is_streaming] => [streaming_eol] => [streaming_metrics_interval] => 60 [as_header] => 1 [multipart] => 1 ) [method] => POST [url] => https://upload.twitter.com/1/statuses/update_with_media.json [request_params] => Array ( [media[]] => @./../images/appstore_icon.png [status] => Don't slip up ) [signing_params] => oauth_consumer_key=nY4E8qXJVxICLYTs9R2BLQ&oauth_nonce=dfac47eb37ca8897cf2542123d1638f9&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1313638299&oauth_token=129314956-PJCTyRqrhoTr5IyLGkma9CjDbss5Uohtml2qMmll&oauth_version=1.0 [auth_params] => Array ( [oauth_consumer_key] => nY4E8qXJVxICLYTs9R2BLQ [oauth_nonce] => dfac47eb37ca8897cf2542123d1638f9 [oauth_signature] => lHjemKp%2BJVmVgD3cQ9ady4Qb66o%3D [oauth_signature_method] => HMAC-SHA1 [oauth_timestamp] => 1313638299 [oauth_token] => 129314956-PJCTyRqrhoTr5IyLGkma9CjDbss5Uohtml2qMmll [oauth_version] => 1.0 ) [base_string] => POST&https%3A%2F%2Fupload.twitter.com%2F1%2Fstatuses%2Fupdate_with_media.json&oauth_consumer_key%3DnY4E8qXJVxICLYTs9R2BLQ%26oauth_nonce%3Ddfac47eb37ca8897cf2542123d1638f9%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1313638299%26oauth_token%3D129314956-PJCTyRqrhoTr5IyLGkma9CjDbss5Uohtml2qMmll%26oauth_version%3D1.0 [signing_key] => 64UGkGOcwqAKSLieXHOVBFgkXFJujYFkhzYTd1Yjls&udoKo0bRmNcKY9WIHEi8cWDMldPS5PyGYEgrYWRcWPk [auth_header] => OAuth oauth_consumer_key="nY4E8qXJVxICLYTs9R2BLQ", oauth_nonce="dfac47eb37ca8897cf2542123d1638f9", oauth_signature="lHjemKp%2BJVmVgD3cQ9ady4Qb66o%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1313638299", oauth_token="129314956-PJCTyRqrhoTr5IyLGkma9CjDbss5Uohtml2qMmll", oauth_version="1.0" [response] => Array ( [headers] => Array ( [date] => Thu, 18 Aug 2011 03:29:36 GMT [server] => hi [status] => 200 OK [x_transaction] => 1313638175-75577-25147 [x_mediaratelimit_remaining] => 12 [x_mediaratelimit_class] => photos [etag] => "e8f1edd9abbb4ba6c9b92464ec4e2847" [last_modified] => Thu, 18 Aug 2011 03:29:35 GMT [x_frame_options] => SAMEORIGIN [x_mediaratelimit_limit] => 30 [content_type] => application/json; charset=utf-8 [x_transaction_mask] => a6183ffa5f8ca943ff1b53b5644ef114b7a0cbbd [x_runtime] => 0.51368 [pragma] => no-cache [content_length] => 2580 [x_access_level] => read-write [x_mediaratelimit_reset] => 1313722601 [cache_control] => no-cache, no-store, must-revalidate, pre-check=0, post-check=0 [expires] => Tue, 31 Mar 1981 05:00:00 GMT [x_revision] => DEV [x_mid] => 38cf611ea13ba444edf613338dacef6a5cb496e3 [set_cookie] => _twitter_sess=BAh7CjoMY3NyZl9pZCIlOWE2YjA3NWMyZTJiZTliZjllZmI4MzkwYzQxYTdh%250AZDM6D2NyZWF0ZWRfYXRsKwgK1O%252FaMQE6B3VhIh90aGVtYXR0aGFycmlzJyBI%250AVFRQIENsaWVudDoHaWQiJTZkZDc1MjNkZjQ1NTlhZjMwODVlMzQ3M2NjNjg5%250AY2FlIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVyOjpGbGFzaDo6Rmxhc2hI%250AYXNoewAGOgpAdXNlZHsA--0657ee6f8e05f42d4eb8ec769f4b445348bbee9c; domain=.twitter.com; path=/; HttpOnly [vary] => Accept-Encoding [connection] => close ) [code] => 200 [response] => {"text":"Don't slip up http:\/\/t.co\/lt5DjR6","id_str":"104032165674749952","in_reply_to_status_id":null,"favorited":false,"in_reply_to_status_id_str":null,"created_at":"Thu Aug 18 03:29:36 +0000 2011","entities":{"hashtags":[],"media":[{"type":"photo","url":"http:\/\/t.co\/lt5DjR6","media_url":"http:\/\/p.twimg.com\/AXGYtBiCEAEmcBL.png","indices":[14,33],"id_str":"104032165678944257","expanded_url":"http:\/\/twitter.com\/yourwaywebsites\/status\/104032165674749952\/photo\/1","display_url":"pic.twitter.com\/lt5DjR6","media_url_https":"https:\/\/p.twimg.com\/AXGYtBiCEAEmcBL.png","sizes":{"thumb":{"w":150,"h":150,"resize":"crop"},"small":{"w":1018,"h":331,"resize":"fit"},"large":{"w":1018,"h":331,"resize":"fit"},"medium":{"w":1018,"h":331,"resize":"fit"}},"id":104032165678944257}],"urls":[],"user_mentions":[]},"in_reply_to_screen_name":null,"source":"\u003Ca href=\"http:\/\/myflashpics.com\/\" rel=\"nofollow\"\u003EFlashPics\u003C\/a\u003E","in_reply_to_user_id_str":null,"contributors":null,"place":null,"retweeted":false,"in_reply_to_user_id":null,"geo":null,"user":{"follow_request_sent":false,"contributors_enabled":false,"favourites_count":0,"profile_sidebar_fill_color":"dbdbdb","url":"http:\/\/www.yourwaywebsites.com\/","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/795852708\/twittericon_normal.png","location":"","id_str":"129314956","notifications":false,"profile_background_tile":false,"description":"Hello, I am Brandon Vento, the founder of Your Way Websites. Our company is a small business that provides web design services to a variety of clients. ","show_all_inline_media":false,"geo_enabled":false,"lang":"en","created_at":"Sat Apr 03 22:20:26 +0000 2010","profile_link_color":"383838","profile_image_url":"http:\/\/a3.twimg.com\/profile_images\/795852708\/twittericon_normal.png","listed_count":0,"profile_sidebar_border_color":"c7c7c7","time_zone":null,"screen_name":"yourwaywebsites","profile_use_background_image":false,"statuses_count":10,"friends_count":9,"profile_background_color":"292727","protected":false,"default_profile_image":false,"following":false,"verified":false,"profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","followers_count":2,"name":"Your Way Websites","default_profile":false,"id":129314956,"is_translator":false,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","utc_offset":null,"profile_text_color":"575757"},"retweet_count":0,"coordinates":null,"truncated":false,"id":104032165674749952,"possibly_sensitive":false} [info] => Array ( [url] => https://upload.twitter.com/1/statuses/update_with_media.json [content_type] => application/json; charset=utf-8 [http_code] => 200 [header_size] => 1563 [request_size] => 559 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 1.286434 [namelookup_time] => 0.123698 [connect_time] => 0.187714 [pretransfer_time] => 0.432981 [size_upload] => 20560 [size_download] => 2580 [speed_download] => 2005 [speed_upload] => 15982 [download_content_length] => 2580 [upload_content_length] => 20560 [starttransfer_time] => 0.433422 [redirect_time] => 0 [request_header] => POST /1/statuses/update_with_media.json HTTP/1.1 User-Agent: themattharris' HTTP Client Host: upload.twitter.com Accept: */* Authorization: OAuth oauth_consumer_key="nY4E8qXJVxICLYTs9R2BLQ", oauth_nonce="dfac47eb37ca8897cf2542123d1638f9", oauth_signature="lHjemKp%2BJVmVgD3cQ9ady4Qb66o%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1313638299", oauth_token="129314956-PJCTyRqrhoTr5IyLGkma9CjDbss5Uohtml2qMmll", oauth_version="1.0" Content-Length: 20560 Content-Type: multipart/form-data; boundary=----------------------------258aadd70f93 ) ) ) 
  • 写回答

2条回答 默认 最新

  • dongzituo5530 2011-08-18 20:55
    关注

    This is what I had to do:

    $thing = json_decode($tmhOAuth->response['response']);
    $tweet_id = $thing->id_str;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler