{"id":786,"date":"2014-10-07T09:08:22","date_gmt":"2014-10-07T09:08:22","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=786"},"modified":"2015-08-17T06:14:28","modified_gmt":"2015-08-17T06:14:28","slug":"tmhoauth-twitter-api-stopped-working-with-update_with_media-call","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/stack-overflow\/tmhoauth-twitter-api-stopped-working-with-update_with_media-call\/","title":{"rendered":"tmhOauth twitter api stopped working with update_with_media call"},"content":{"rendered":"<p><a href=\"http:\/\/stackoverflow.com\/users\/534755\/nikola\"><img loading=\"lazy\" decoding=\"async\" title=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" src=\"http:\/\/stackoverflow.com\/users\/flair\/534755.png\" rel=\"lightbox[786]\" alt=\"profile for Nikola at Stack Overflow, Q&amp;A for professional and enthusiast programmers\" width=\"208\" height=\"58\" \/><\/a><br \/>\nI&#8217;m a big fan of <a href=\"http:\/\/stackoverflow.com\/\">Stack Overflow<\/a> and I tend to contribute regularly (am currently in the <a href=\"http:\/\/stackexchange.com\/leagues\/1\/alltime\/stackoverflow\/2008-07-31\/534755?sort=reputationchange#534755\">top 0.X%<\/a>).\u00a0In this category (<a href=\"http:\/\/www.nikola-breznjak.com\/blog\/category\/stack-overflow\/\">stackoverflow<\/a>)\u00a0of posts I will will be posting my top rated questions and answers. This, btw, is allowed as explained in the meta thread <a href=\"http:\/\/meta.stackoverflow.com\/questions\/266971\/can-i-post-so-questions-and-answers-in-a-personal-blog\/266973\">here<\/a>.<\/p>\n<p>My <a href=\"http:\/\/stackoverflow.com\/questions\/17060893\/tmhoauth-twitter-api-stopped-working-with-update-with-media-call\">quesiton<\/a> was:<\/p>\n<p style=\"color: #000000;\">So, this morning I got the following error:<\/p>\n<pre style=\"color: #000000;\"><code>{\"errors\": [{\"message\": \"The Twitter REST API v1 will soon stop functioning. \r\nPlease migrate to API v1.1. https:\/\/dev.twitter.com\/docs\/api\/1.1\/overview.\",\r\n\"code\": 68}]}\r\n<\/code><\/pre>\n<p style=\"color: #000000;\">Since I was using the\u00a0<a style=\"color: #4a6b82;\" href=\"https:\/\/github.com\/themattharris\/tmhOAuth\" rel=\"nofollow\">tmhOauth twitter api<\/a>\u00a0I went to look if there are updates for it, and as it seems there is an issue listed\u00a0<a style=\"color: #4a6b82;\" href=\"https:\/\/github.com\/themattharris\/tmhOAuth\/issues\/132\" rel=\"nofollow\">here<\/a>.<\/p>\n<p style=\"color: #000000;\">I&#8217;m using the api to update the status with media like this:<\/p>\n<pre style=\"color: #000000;\"><code>$code = $tmhOAuth-&gt;request('POST', 'https:\/\/upload.twitter.com\/1\/statuses\/update_with_media.json',\r\n        array(\r\n            'media[]'  =&gt; \"@{$image}\",\r\n            'status'   =&gt; \"{$text}\"\r\n        ),\r\n        true, \/\/ use auth\r\n        true  \/\/ multipart\r\n);\r\n<\/code><\/pre>\n<p style=\"color: #000000;\">I found notes that I should just change the link to use\u00a0<code>1.1<\/code>\u00a0instead of\u00a0<code>1<\/code>\u00a0but it&#8217;s still not working.<\/p>\n<p style=\"color: #000000;\"><span style=\"line-height: 1.5;\">I actually answered this one my self after finding the solution:<\/span><\/p>\n<blockquote>\n<p style=\"color: #000000;\">My main problem was that I didn&#8217;t read the docs fully! While the change in the url from\u00a0<code>1<\/code>\u00a0to\u00a0<code>1.1<\/code>\u00a0was sufficient I missed the point by not looking that the new url for update_with_media, as explained in the<a style=\"color: #4a6b82;\" href=\"https:\/\/dev.twitter.com\/docs\/api\/1.1\/post\/statuses\/update_with_media\" rel=\"nofollow\">documentation<\/a>, is\u00a0<code>https:\/\/api.twitter.com\/1.1\/statuses\/update_with_media.json<\/code>, namely it&#8217;s\u00a0<strong>api<\/strong>\u00a0instead of the old\u00a0<strong>upload<\/strong>\u00a0subdomain.<\/p>\n<p style=\"color: #000000;\">So, now my api call looks like this and all works again:<\/p>\n<pre style=\"color: #000000;\"><code>$code = $tmhOAuth-&gt;request('POST', 'https:\/\/api.twitter.com\/1.1\/statuses\/update_with_media.json',\r\n        array(\r\n            'media[]'  =&gt; \"@{$image}\",\r\n            'status'   =&gt; \"{$text}\"\r\n        ),\r\n        true, \/\/ use auth\r\n        true  \/\/ multipart\r\n    );\r\n<\/code><\/pre>\n<p style=\"color: #000000;\">Hope this helps someone.<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m a big fan of Stack Overflow and I tend to contribute regularly (am currently in the top 0.X%).\u00a0In this category (stackoverflow)\u00a0of posts I will will be posting&hellip;<\/p>\n","protected":false},"author":1,"featured_media":609,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-786","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-stack-overflow"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=786"}],"version-history":[{"count":2,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/786\/revisions"}],"predecessor-version":[{"id":1708,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/786\/revisions\/1708"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/609"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}