Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No media uploaded only status #274

Closed
koese66 opened this issue Feb 8, 2019 · 23 comments
Closed

No media uploaded only status #274

koese66 opened this issue Feb 8, 2019 · 23 comments

Comments

@koese66
Copy link

koese66 commented Feb 8, 2019

Hello @J7mbo here is my code:
`function MediaUpload($temp) {

global $settings;
$settings=array_merge($settings,["Content-Type"=>"multipart/form-data"]);

// Upload image to twitter
$url = "https://upload.twitter.com/1.1/media/upload.json";
$requestMethod = "POST";
$media = file_get_contents($temp);
$params = array(
    "media" => $media,
);

$twitter = new TwitterAPIExchange($settings);
$res = $twitter->setPostFields($params)
    ->buildOauth($url, $requestMethod)
    ->performRequest();

// Result is a json string
$result = json_decode($res);
$media_ids = $result->media_id_string;
StatusesUpdate($media_ids);

}

function StatusesUpdate($media_ids)
{
global $settings;
if (!$media_ids)
{
$this->fail('Cannot /update status because /upload failed');
}
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$method = 'POST';
$params = array(
'status' => 'mypage.de',
'possibly_sensitive' => false,
'media_ids' => $media_ids
);

$twitter = new TwitterAPIExchange($settings);

$resultat = $twitter->setPostfields($params)
    ->buildOauth($url, $method)
    ->performRequest();

$result = @json_decode($resultat, true);
return $result;

}`

@koese66
Copy link
Author

koese66 commented Feb 8, 2019

Sorry $ temp is
/www/htdocs/wxxxxx3/images/product_images/popup_images/53517_0.jpg
and $media_id ist something like this 1093901498696756789

@koese66
Copy link
Author

koese66 commented Feb 8, 2019

$result is following:
/www/htdocs/wxxxxx/images/product_images/popup_images/53517_0.jpgArray ( [created_at] => Fri Feb 08 15:49:54 +0000 2019 [id] => 1093899731925979137 [id_str] => 1093899731925979137 [text] => https://t.co/JJjaFfffo5ME0 [truncated] => [entities] => Array ( [hashtags] => Array ( ) [symbols] => Array ( ) [user_mentions] => Array ( ) [urls] => Array ( [0] => Array ( [url] => https://t.co/JJjaFofff5ME0 [expanded_url] => http://mypage.de [display_url] => mypage.de [indices] => Array ( [0] => 0 [1] => 23 ) ) ) ) [source] => mypage.de [in_reply_to_status_id] => [in_reply_to_status_id_str] => [in_reply_to_user_id] => [in_reply_to_user_id_str] => [in_reply_to_screen_name] => [user] => Array ( [id] => 272901659 [id_str] => 272901659 [name] => mypage.de [screen_name] => mypage [location] => Gotha [description] => https://t.co/zODg2HBZkX Schuh- und Accessoires-Einkauf im Internet. Impressum: https://t.co/WEdfd1lrq1YOS [url] => http://www.mypage.de [entities] => Array ( [url] => Array ( [urls] => Array ( [0] => Array ( [url] => http://www.mypage.de [expanded_url] => http://www.mypage.de [display_url] => mypage.de [indices] => Array ( [0] => 0 [1] => 22 ) ) ) ) [description] => Array ( [urls] => Array ( [0] => Array ( [url] => https://t.co/zODgdfd2HBZkX [expanded_url] => http://mypage.de [display_url] => mypage.de [indices] => Array ( [0] => 0 [1] => 23 ) ) [1] => Array ( [url] => https://t.co/WE1ffdflrq1YOS [expanded_url] => http://tinyurl.com/ycfdf4sq5ow [display_url] => tinyurl.com/yc4sq5ow [indices] => Array ( [0] => 141 [1] => 164 ) ) ) ) ) [protected] => [followers_count] => 722 [friends_count] => 1796 [listed_count] => 26 [created_at] => Sun Mar 27 12:05:53 +0000 2011 [favourites_count] => 0 [utc_offset] => [time_zone] => [geo_enabled] => [verified] => [statuses_count] => 10251 [lang] => de [contributors_enabled] => [is_translator] => [is_translation_enabled] => [profile_background_color] => C0DEED [profile_background_image_url] => http://abs.twimg.com/images/themes/theme1/bg.png [profile_background_image_url_https] => https://abs.twimg.com/images/themes/theme1/bg.png [profile_background_tile] => [profile_image_url] => http://pbs.twimg.com/profile_images/1290282823/mypage_1600x1600neu_normal.jpg [profile_image_url_https] => https://pbs.twimg.com/profile_images/1290282823/mypage_1600x1600neu_normal.jpg [profile_banner_url] => https://pbs.twimg.com/profile_banners/272901659/1431091458 [profile_link_color] => 1DA1F2 [profile_sidebar_border_color] => C0DEED [profile_sidebar_fill_color] => DDEEF6 [profile_text_color] => 333333 [profile_use_background_image] => 1 [has_extended_profile] => [default_profile] => 1 [default_profile_image] => [following] => [follow_request_sent] => [notifications] => [translator_type] => none ) [geo] => [coordinates] => [place] => [contributors] => [is_quote_status] => [retweet_count] => 0 [favorite_count] => 0 [favorited] => [retweeted] => [possibly_sensitive] => [lang] => und )

@koese66
Copy link
Author

koese66 commented Feb 11, 2019

@J7mbo do you need something else?

@J7mbo
Copy link
Owner

J7mbo commented Feb 13, 2019

Hey @koese66, looks like you get a result. So what exactly is the problem? Looks like you get a media id in the first step, which is what you want, and then you try and upload it.

@koese66
Copy link
Author

koese66 commented Feb 13, 2019

Hey @J7mbo I cant see my post with the image. There is only the staus written.See here: https://twitter.com/schuhfachmann
Since 24.10.2018 it looks like there is a problem.

@J7mbo
Copy link
Owner

J7mbo commented Feb 13, 2019

Okay, can you please run this code, separate from any other code that you are running. Just open a plain PHP script, put in the configuration required to make $twitterApiExchange object, and then use this code below.

Make sure you insert a proper path to your image, and some text for your tweet.

Can you let me know the result on your twitter account?

    /* Upload image */       
    $file = file_get_contents('INSERT PATH TO YOUR IMAGE');
    $data = base64_encode($file);
    $url    = 'https://upload.twitter.com/1.1/media/upload.json';
    $method = 'POST';
    $params = array(
        'media_data' => $data
    );
    $data     = $twitterApiExchange->request($url, $method, $params);

    /** Store the media id for later **/
    $data = @json_decode($data, true);
    
    $mediaId = $data['media_id'];

   /* Create tweet and reference image */
    $url    = 'https://api.twitter.com/1.1/statuses/update.json';
    $method = 'POST';
    $params = [
        'status' => 'PUT YOUR STATUS TEXT HERE',
        'possibly_sensitive' => false,
        'media_ids' => $mediaId
    ];
    $data     = $twitterApiExchange->request($url, $method, $params);
   
    $data = @json_decode($data, true);
    var_dump($data);

@koese66
Copy link
Author

koese66 commented Feb 13, 2019

There seems to be a problem with this part of code:
$data = $twitterApiExchange->request($url, $method, $params);
I get a error page with this message "This page does not work"

@koese66
Copy link
Author

koese66 commented Feb 13, 2019

I use this part of code and I get the media ID in the first step
$twitter = new TwitterAPIExchange($settings); $result = $twitter->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest();

@J7mbo
Copy link
Owner

J7mbo commented Feb 13, 2019

Ah. Create a new twitter api exchange object for the second request and use that one instead.

@koese66
Copy link
Author

koese66 commented Feb 13, 2019

You mean this?
$twitter = new TwitterAPIExchange($settings); $data = $twitter->request($url, $method, $params);

Right? This also doesnt work.

@J7mbo
Copy link
Owner

J7mbo commented Feb 13, 2019

You get an error with "This page does not work" - but I'm not sure where this error message comes from. It could come from your web server or a framework, but it doesn't look like it comes from the API call nor from any custom error messages in the library code.

Can you put the code into a simple PHP script (.php) and then execute that php script with nothing else in it?

@J7mbo
Copy link
Owner

J7mbo commented Feb 13, 2019

If you have access to terminal, running "php myscript.php" will be good enough.

@koese66
Copy link
Author

koese66 commented Feb 13, 2019

Fatal error: Call to a member function request() on null in /www/htdocs/xxxxxx/myscript.php on line 11

@J7mbo
Copy link
Owner

J7mbo commented Feb 13, 2019

Debugging time - why is your $twitterApiExchange null?

@koese66
Copy link
Author

koese66 commented Feb 13, 2019

Now I get it. Here is the var_dump

array(23) { ["created_at"]=> string(30) "Wed Feb 13 15:48:03 +0000 2019" ["id"]=> int(1095711206084624384) ["id_str"]=> string(19) "1095711206084624384" ["text"]=> string(6) "Rieker" ["truncated"]=> bool(false) ["entities"]=> array(4) { ["hashtags"]=> array(0) { } ["symbols"]=> array(0) { } ["user_mentions"]=> array(0) { } ["urls"]=> array(0) { } } ["source"]=> string(74) "Schuhfachmann.de" ["in_reply_to_status_id"]=> NULL ["in_reply_to_status_id_str"]=> NULL ["in_reply_to_user_id"]=> NULL ["in_reply_to_user_id_str"]=> NULL ["in_reply_to_screen_name"]=> NULL ["user"]=> array(42) { ["id"]=> int(272901659) ["id_str"]=> string(9) "272901659" ["name"]=> string(16) "Schuhfachmann.de" ["screen_name"]=> string(13) "schuhfachmann" ["location"]=> string(5) "Gotha" ["description"]=> string(166) "https://t.co/zODg2HBZkX ist Ihr zuverlässiger Modepartner für den unkomplizierten Schuh- und Accessoires-Einkauf im Internet. Impressum: https://t.co/WE1lrq1YOS" ["url"]=> string(22) "http://t.co/5bER2wLsrp" ["entities"]=> array(2) { ["url"]=> array(1) { ["urls"]=> array(1) { [0]=> array(4) { ["url"]=> string(22) "http://t.co/5bER2wLsrp" ["expanded_url"]=> string(27) "http://www.schuhfachmann.de" ["display_url"]=> string(16) "schuhfachmann.de" ["indices"]=> array(2) { [0]=> int(0) [1]=> int(22) } } } } ["description"]=> array(1) { ["urls"]=> array(2) { [0]=> array(4) { ["url"]=> string(23) "https://t.co/zODg2HBZkX" ["expanded_url"]=> string(23) "http://Schuhfachmann.de" ["display_url"]=> string(16) "Schuhfachmann.de" ["indices"]=> array(2) { [0]=> int(0) [1]=> int(23) } } [1]=> array(4) { ["url"]=> string(23) "https://t.co/WE1lrq1YOS" ["expanded_url"]=> string(27) "http://tinyurl.com/yc4sq5ow" ["display_url"]=> string(20) "tinyurl.com/yc4sq5ow" ["indices"]=> array(2) { [0]=> int(141) [1]=> int(164) } } } } } ["protected"]=> bool(false) ["followers_count"]=> int(720) ["friends_count"]=> int(1794) ["listed_count"]=> int(26) ["created_at"]=> string(30) "Sun Mar 27 12:05:53 +0000 2011" ["favourites_count"]=> int(0) ["utc_offset"]=> NULL ["time_zone"]=> NULL ["geo_enabled"]=> bool(false) ["verified"]=> bool(false) ["statuses_count"]=> int(10252) ["lang"]=> string(2) "de" ["contributors_enabled"]=> bool(false) ["is_translator"]=> bool(false) ["is_translation_enabled"]=> bool(false) ["profile_background_color"]=> string(6) "C0DEED" ["profile_background_image_url"]=> string(48) "http://abs.twimg.com/images/themes/theme1/bg.png" ["profile_background_image_url_https"]=> string(49) "https://abs.twimg.com/images/themes/theme1/bg.png" ["profile_background_tile"]=> bool(false) ["profile_image_url"]=> string(84) "http://pbs.twimg.com/profile_images/1290282823/schuhfachmann_1600x1600neu_normal.jpg" ["profile_image_url_https"]=> string(85) "https://pbs.twimg.com/profile_images/1290282823/schuhfachmann_1600x1600neu_normal.jpg" ["profile_banner_url"]=> string(58) "https://pbs.twimg.com/profile_banners/272901659/1431091458" ["profile_link_color"]=> string(6) "1DA1F2" ["profile_sidebar_border_color"]=> string(6) "C0DEED" ["profile_sidebar_fill_color"]=> string(6) "DDEEF6" ["profile_text_color"]=> string(6) "333333" ["profile_use_background_image"]=> bool(true) ["has_extended_profile"]=> bool(false) ["default_profile"]=> bool(true) ["default_profile_image"]=> bool(false) ["following"]=> bool(false) ["follow_request_sent"]=> bool(false) ["notifications"]=> bool(false) ["translator_type"]=> string(4) "none" } ["geo"]=> NULL ["coordinates"]=> NULL ["place"]=> NULL ["contributors"]=> NULL ["is_quote_status"]=> bool(false) ["retweet_count"]=> int(0) ["favorite_count"]=> int(0) ["favorited"]=> bool(false) ["retweeted"]=> bool(false) ["lang"]=> string(2) "nl" }

@koese66
Copy link
Author

koese66 commented Feb 13, 2019

The function request wasnt in the TwitterAPIExchange.php
Look at my twitter account there is only the status

@J7mbo
Copy link
Owner

J7mbo commented Feb 13, 2019

Are you using an old version of the lib? That function has been there for a while now...

@koese66
Copy link
Author

koese66 commented Feb 13, 2019

Perhaps 2 years...

@J7mbo
Copy link
Owner

J7mbo commented Feb 13, 2019

Hope all is solved now? :)

@koese66
Copy link
Author

koese66 commented Feb 13, 2019

no there is no solution yet :) I can only see my status posted. Do you see the product image?
https://twitter.com/schuhfachmann
There is only Rieker writing...

@J7mbo
Copy link
Owner

J7mbo commented Feb 13, 2019

And you are definitely running the code I put above, with only minor changes to use your image and tweet text, and running php myscript.php?

@koese66
Copy link
Author

koese66 commented Feb 13, 2019

I have only additional code to get my status and the image from database.
But also without this additional code it doesn't work. Please look here:

`<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

require $_SERVER['DOCUMENT_ROOT'] . "includes/application_top_export.php";
require "TwitterAPIExchange.php";

$settings = array(
'oauth_access_token' => "xxxxxxxxxxxxxxxxxxxx",
'oauth_access_token_secret' => "xxxxxxxxxxxxxxxxxxxxxxxxx",
'consumer_key' => "xxxxxxxxxxxxxxxxxxx",
'consumer_secret' => "xxxxxxxxxxxxxxxxxxxx",
);

$error = false;
$media_files = array();
$text_limit = 118;

/* Upload image */
$file = file_get_contents('https://www.schuhfachmann.de/cms/upload/content/filialen/leifer_eisenach_vorschau.jpg');
$data = base64_encode($file);
$url = 'https://upload.twitter.com/1.1/media/upload.json';
$method = 'POST';
$params = array(
'media_data' => $data
);

$twitter = new TwitterAPIExchange($settings);
$data = $twitter->request($url, $method, $params);

/** Store the media id for later **/
$data = @json_decode($data, true);

$mediaId = $data['media_id'];

/* Create tweet and reference image */
$url = 'https://api.twitter.com/1.1/statuses/update.json';
$method = 'POST';
$params = [
'status' => 'this is my status test',
'possibly_sensitive' => false,
'media_ids' => $mediaId
];
$data = $twitter->request($url, $method, $params);

$data = @json_decode($data, true);
var_dump($data);

?>`

@koese66
Copy link
Author

koese66 commented Feb 15, 2019

@J7mbo Can you help me now :)

@koese66 koese66 closed this as completed Feb 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants