I'm looking for a way to use this to upload photos to Twitter that have been attached to nodes. I believe this is possible per this item in Twitter's documentation pages:

https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media

Is anyone doing this already? Being able to add a photo and not just a link to the node would be a great advancement.

My team would be willing to work with anyone who is already working on this, or we may be able to tackle it ourselves.

Thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jmrivero’s picture

twitter.lib.php has a statuses_update_with_media but there is a "@TODO support media at TwitterStatus class." in it, looking at twitterstatus class the support for media is not implemented yet.

jmrivero’s picture

Well, I think I got to handle media in TwitterStatus class by adding the following to the __construct:

$this->entities = $values['entities'];

This will add an array to the status object containing the hashtags, media, urls and user_mentions as described in the response in https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media
Then the images attached can be accesed in the statuses with:

 $status->entities['media'][0]['media_url']

This is just some hack in the air, the module doesnt use this entities and I am still trying to figure how to post to twitter with media, I have tryed to set the headers to multipart/form-data if the media param is set in request of the Twitter class like this but it doesnt seem to work so far:

if(isset($params['media[]']))
        $headers['Content-type'] = 'multipart/form-data';
    else
        $headers['Content-type'] = 'application/x-www-form-urlencoded';

Then added a function in twitter.inc to set a status with media:

/**
 * Post a message with media to twitter
 *
 * @param $twitter_account
 *   object with a Twitter account.
 * @param $status
 *   string message to publish.
 * @param $media_urls
 *   array with media urls.
 * @return
 *   array response from Twitter API.
 */
function twitter_set_status_with_media($twitter_account, $status,$media_urls) {
  $twitter = twitter_connect($twitter_account);
  return $twitter->statuses_update_with_media($status,$media_urls);
}

Dosnt work so im just sharing some ideas while toying with it, hope it helps.

jmrivero’s picture

Component: Miscellaneous » Twitter API
Category: feature » task
jmrivero’s picture

Using tmhOauth while this feature is implemented calling this function with rules on each cron run:

function mymodule_post_image_to_twitter($msg,$image_url){
    module_load_include('inc', 'twitter');
    $account = twitter_account_load("MyTwitterHandle");
    $auth = $account->get_auth();
    require DRUPAL_ROOT . '/'. drupal_get_path('module', 'mymodule') . '/lib/tmh/tmhOAuth.php';

    $tmhOAuth = new tmhOAuth(array(
      'consumer_key'    => variable_get('twitter_consumer_key', ''),
      'consumer_secret' => variable_get('twitter_consumer_secret', ''),
      'user_token'      => $auth['oauth_token'],
      'user_secret'     => $auth['oauth_token_secret'],
    ));

    $code = $tmhOAuth->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json',
      array(
        'media[]'  => file_get_contents($image_url),
        'status'   => $msg,
      ),
      true, // use auth
      true  // multipart
    );
    
    return $code;
}
drasgardian’s picture

Version: 7.x-5.7 » 7.x-5.x-dev
Issue summary: View changes
Status: Active » Needs review
FileSize
6.83 KB

Here is a patch that adds support for media in the TwitterStatus class.

It also fetches the configuration settings from twitter (as per https://dev.twitter.com/rest/reference/get/help/configuration) to verify how many images can be uploaded. So when twitter starts accepting more than one image this will start allowing more than one image to be sent in the request.
The helper function current_configuration() might be useful elsewhere.

errand’s picture

I've installed dev version of the module.
What else should i do to make it post images too?

DamienMcKenna’s picture

Status: Needs review » Needs work

Triggering the testbot.

DamienMcKenna’s picture

Status: Needs work » Needs review

Triggering the testbot.

jwilson3’s picture

Status: Needs review » Needs work

Patch looks good so far, but it only really adds the media support to the twitter.lib.php which I haven't honestly tested yet because as far as I can tell, the statuses_update_with_media() function is never called anywhere throughout the module's codebase. So, there is more work to be done here, and the question is how exactly to integrate the media functionality into the Twitter module's existing features?

I think the integration should be two-fold:

1) integrate with Content-type based twitter_post submodule (admin/config/services/twitter/post):

For each content type in the list that is enabled:
* Allow admin to pick which image style to use, and
* Provide a way to select which image field to use, if there are multiple image fields.
* Investigate and test Twitter support for multiple media files (mentioned above) using Drupal image fields with multiple cardinality.

2) integrate with the Rules-based twitter_actions submodule:

* Create a new action called "Post a message with media to Twitter".
* Works the same way as existing "Post a message to Twitter" action, but in addition to the "Message" parameter, accepts a second "Media" parameter.
* Investigate support for multiple media files (mentioned above) using Drupal image fields with multiple cardinality.

sarhugo’s picture

Also the statuses/update_with_media endpoint has been DEPRECATED.
It should first upload the media through media/upload and then attach the media's id to the status.

MickC’s picture

Patch not working for me - instead of an image I see text only of 'Property' + the field name, in my case - "Property field_tweet_image"

intrafusion’s picture

Title: Uploading images » Support media/upload endpoint
Status: Needs work » Needs review
FileSize
8.41 KB

Seeing as the statuses/update_with_media endpoint has been deprecated, I have started work on using the media/upload endpoint instead.

Here is a patch the start the process which does the following:

1. Defines TWITTER_UPLOAD constant of https://upload.twitter.com
2. Allows twitter_upload variable to be edited on admin/config/services/twitter/settings
3. Creates new function twitter_upload_media to facilitate upload
4. Several updates to twitter.lib.php which actually uploads the media, a lot of the changes were taken from the changes in #5

To use these changes you will need to manually code them via:

$file = file_load(XXX); // The image which needs uploading
$path = drupal_realpath($file->uri);
$handle = fopen($path, "r");
$contents = fread($handle, filesize($path));
fclose($handle);

module_load_include('inc', 'twitter');
$account = twitter_account_load(XXX); // The twitter account name or id
$media = twitter_upload_media($account, $file->filename, $file->filemime, $contents);

The next stage (assuming that this is OK) would be to integrate this into twitter_set_status function as the returned media id can be used in the media_ids parameter of the statuses/update endpoint

DamienMcKenna’s picture

Category: Task » Feature request
DamienMcKenna’s picture

@intrafusion: Thanks for working on this. I think it'd be useful to be able to use a token / selector to indicate what field to use - how often do people want to upload an image to Twitter that isn't already in their node?

intrafusion’s picture

@DamienMcKenna I totally agree but think we need full token support as per #1441596: Add support for tokens module on twitter post. before we can do that.

My work up till now was handling the actual posting to Twitter.

intrafusion’s picture

intrafusion’s picture

Status: Needs review » Needs work

@DamienMcKenna, upon further work I'm not sure how easy this will be to do.

Firstly, to be able to pull the correct value via a token we need Entity Tokens (part of Entity API).

Secondly, #2165511: Multi-value File Field Token with :file property is empty means that if you have a multi-value field rather than using [node:field-image:file], you need to use [node:field-image:0:file], [node:field-image:1:file], etc.

Thirdly, the file tokens comprise of fid, name, mime, size, url, timestamp & owner values meaning that fid is the only really usable token meaning the user would need supply [node:field-image:file:fid] or [node:field-image:0:file:fid], [node:field-image:0:file:fid], etc. which seems to open a whole realm for mistakes, etc.

Wondered whether you had any additional ideas how this could be accomplished?

doitDave’s picture

I consider media handling (and doing it with full media module benefits) a major item that will also add much of even more value to the module.

I would like to suggest an even more comfortable improved/advanced Twitter post field (see also #2474157: Add non-"hidden" field formatter for "Twitter field") or rather field collection, maybe even overridable in order to use arbitrary media selectors like MBP, IMCE or whatever. Media selected there will first be uploaded and then either mapped to an entered placeholder or, if that is not present, simply appended to the tweet (which is eventually shortened).

What do you think?

Andre-B’s picture

just an idea: why not expose a configurable token with this module? e.g. add a setting on image fields to expose them in a way they are addressable for twitter posting? And also state there that the nth element will be taken (e.g. first,). that way we could add logic ourselves?

petrovnn’s picture

intrafusion, in what file needed is to write the code? In the module file?

To use these changes you will need to manually code them via:
<?php
$file = file_load(XXX); // The image which needs uploading
.....

from your comment #12.
patch applied successfully

intrafusion’s picture

@petrovnn you will need to use this code in a custom module. For my instance I was taking newly uploaded media and posting it to Twitter, so I used hook_node_insert($node) & hook_node_update($node), but I simplified the example code I posted

petrovnn’s picture

so, my code looks like:

/*  NODE INSERT  */
function my_module_node_update($node) {
	$file = file_load($node->field_plugin_img['und'][0]['fid']); // The image which needs uploading
	$path = drupal_realpath($file->uri);
	$handle = fopen($path, "r");
	$contents = fread($handle, filesize($path));
	fclose($handle);

	module_load_include('inc', 'twitter');
	$account = twitter_account_load('plugindetector'); // The twitter account name or id
	$media = twitter_upload_media($account, $file->filename, $file->filemime, $contents);
}

but i have this error:

PHP Fatal error:  Call to a member function media_upload() on a non-object in /sites/all/modules/twitter/twitter.inc on line 306, referer: /node/107/edit

what can you recommend?
Posting with pictures is very necessary.

It can be bad patching?
what program do you recommend for patches?

Line, which causes an error:

return $twitter->media_upload($filename, $filemime, $media);

in function:

function twitter_upload_media($twitter_account, $filename, $filemime, $media) {
  $twitter = twitter_connect($twitter_account);
  return $twitter->media_upload($filename, $filemime, $media);
}

Google gave me two links
http://stackoverflow.com/a/54572
http://stackoverflow.com/a/14242492

intrafusion’s picture

Looks like:

$twitter = twitter_connect($twitter_account);

Is not returning an object, is the account name correct?

petrovnn’s picture

is the account name correct?

yes.

so, database logging noticed:

There are no authenticated Twitter accounts to use for API connections.

But i have authenticated account: http://i.imgur.com/82sPQoE.png
and have registered twitter application http://i.imgur.com/yZLDIrn.png

maybe me need to learn how correctly configure twitter module?

but before patching I have already published tweets (without pictures) without any problems with these same settings: http://i.imgur.com/GKgcDDl.png

petrovnn’s picture

FileSize
52.34 KB
43.99 KB
35.35 KB
30.08 KB
95.3 KB
42.78 KB

I wanted to report some results.

1. The patch could NOT be applied correctly (for the module version 7.x-5.x stable)

PHPStorm:
g1kzHiA.png

s0mcdgz.png

GIT for windows:
60550b8d7a.png

2. The most of the problems caused file twitter.lib.php

3. I applied the patch manually, line by line, the result is: http://pastebin.com/iXqL7r0A
(not copied some php comments)

4. variables from my_module are correct:

1a21ce20e6.png

a146238363.png

5. No errors in dblog
no errors in apache2 error.log
no results after node_save (Posts are not published on twitter at all)

6. patch may be a little outdated?

1VWqN3c.png

7. may be necessary to apply the patch to version 7.x-6.x or DEV?

sorry for such a long comment, but I really need to make post pictures on Twitter

intrafusion’s picture

OK my patch was created against the dev version prior to 7.x-5.9 and there have been fundamental changes to the Twitter module since then.

However, there are bigger problems see #1981472-17: Support media/upload endpoint & #1441596: Add support for tokens module on twitter post.

intrafusion’s picture

Status: Needs work » Needs review
FileSize
8.17 KB

Re-rolled patch from #1981472-12: Support media/upload endpoint against latest dev

DamienMcKenna’s picture

If the API changes work correctly the question then is how to determine a) whether images should be uploaded, b) which images should be uploaded? It shouldn't just automatically upload every image it finds, because thanks to field defaults there could be lots of duplicates.

petrovnn’s picture

FileSize
63.02 KB

intrafusion Excuse me, I not quite understand English, did not understand what it means:

against latest dev

for which version of the module should be applied your patch "Support Media_upload Endpoint-1981472-26.patch"?

6d5bcf09b0.png

However, there are bigger problems see #1981472-17: Support media/upload endpoint & #1441596: Add support for tokens module on twitter post.

Unfortunately, I am not a programmer, and I can not just pick up and fixed a tokens issue in this module.

petrovnn’s picture

I'm not quite understand what it means:

The next stage (assuming that this is OK) would be to integrate this into twitter_set_status function as the returned media id can be used in the media_ids parameter of the statuses/update endpoint

This means i need more changes in some files?
How can i integrate "this into twitter_set_status" function?
from here #12

intrafusion’s picture

@petrovnn the patch should apply cleanly to both versions, but 7.x-5.x-dev was what the patch was created against.

The changes which have been made so far are for the API, as mentioned in #1981472-28: Support media/upload endpoint we need to decide what happens next.

petrovnn’s picture

The changes which have been made so far are for the API, as mentioned in #1981472-28: we need to decide what happens next.

But what should I do next? I do not understand.
The patch was applied successfully, but neither stable nor dev version does not publish pictures to Twitter (publication in Twitter works, but there is no image in the post).

Can-I you somehow help?
Or is it a dead end?

Can I hack, any file or function to get the publication of pictures?

I understand that you want a "clean", "academic" way to upload pictures, but I fear that this will have to wait too long. Is there any faster way to get this functionality from one field as you described here:

function mymodule_node_insert($node) {
	
	$file = file_load($node->field_plugin_img['und'][0]['fid']); // The image which needs uploading
	$path = drupal_realpath($file->uri);
	$handle = fopen($path, "r");
	$contents = fread($handle, filesize($path));
	fclose($handle);

	module_load_include('inc', 'twitter');
	
	//$account = twitter_account_load('plugindetector'); // The twitter account name 
	$account = twitter_account_load('351014461'); // The twitter account id

	$media = twitter_upload_media($account, $file->filename, $file->filemime, $contents);
}

How should I change function twitter_set_status() to attach variable $media to the variable $status?

\sites\all\modules\twitter\twitter.inc

/**
 * Post a message to twitter
 *
 * @param $twitter_account
 *   object with a Twitter account.
 * @param $status
 *   string message to publish.
 * @return
 *   array response from Twitter API.
 */
function twitter_set_status($twitter_account, $status) {
  $twitter = twitter_connect($twitter_account);
  if (empty($twitter)) {
    return FALSE;
  }
  return $twitter->statuses_update($status);
}
intrafusion’s picture

@petrovnn You don't need to change anything else. $media = twitter_upload_media will return an array and $media['media_id'] is what you need:

try {
  $twitter = twitter_connect($account);
  $twitter->statuses_update($status, array(
    'media_ids' => implode(',', $media['media_id'])
  ));
}
catch (Exception $e) {
  $message = $e->getMessage() . ' ' . $e->getTraceAsString() . ' ';
  while($e = $e->getPrevious()) {
    $message .= 'Caused by: ' . $e->getMessage() . ' ' . $e->getTraceAsString() . ' ';
  }
  watchdog('twitter', $message, array(), WATCHDOG_ERROR);
}

$status is the actual 140 characters for the tweet, but you will need to allow approx. 10 characters for each image uploaded and you can only upload 4 images for each tweet

petrovnn’s picture

FileSize
35.3 KB
14.38 KB
28.43 KB

but where I need to insert this code?

try {
  $twitter = twitter_connect($account);
  $twitter->statuses_update($status, array(
    'media_ids' => implode(',', $media['media_id'])
  ));
}
catch (Exception $e) {
  $message = $e->getMessage() . ' ' . $e->getTraceAsString() . ' ';
  while($e = $e->getPrevious()) {
    $message .= 'Caused by: ' . $e->getMessage() . ' ' . $e->getTraceAsString() . ' ';
  }
  watchdog('twitter', $message, array(), WATCHDOG_ERROR);
}

In my module in hook_node_insert (), or in the function twitter_set_status () in file twitter.inc ?

If I add a variable $media to the function twitter_set_status (), there is a message that the variable $media undefined.

I need only one picture in a tweet, can-I to write so?

return $twitter->statuses_update($status, array(
	'media_ids' => $media['media_id']
));

I found only one place where there is a line $ twitter-> statuses update ($ status
in file twitter.inc, function twitter_set_status ($ twitter_account, $ status):

function twitter_set_status($twitter_account, $status) {
  $twitter = twitter_connect($twitter_account);
  if (empty($twitter)) {
    return FALSE;
  }
  
  return $twitter->statuses_update($status);
}

but if i change last string to:

return $twitter->statuses_update($status, array(
	'media_ids' => implode(',', $media['media_id'])
));

PHP return undefined error for variable $media.

At the same time, in a file module function hook_node_insert (), the variable $media exists, and here it is:
fdf8ceae6b.png

but tweets still posting without images:
7f29c81bdf.png

a0e115e32a.png

... and I really do not understand what I'm doing wrong.

cloudbull’s picture

hi,

this patch already merged ? Or i still have to patch it while using the 6.x update ?

cloudbull’s picture

i see there is a function in the patch: twitter_upload_media but never being called. Is that the code updated or ? and tested 5.x-dev with the patch and not working.

Keith

cloudbull’s picture

i just made a success image upload by hacks below

/**
* Post a message to twitter
*
* @param $twitter_account
* object with a Twitter account.
* @param $status
* string message to publish.
* @return
* array response from Twitter API.
*/
function twitter_set_status($twitter_account, $status) {
$twitter = twitter_connect($twitter_account);
if (empty($twitter)) {
return FALSE;
}

// Support media
global $user;
$temp = cache_get('temp_media_ids_' . $user->uid);
$param = array();
if ( $temp ) {// if there is a cache from same user
$param['media_ids'] = $temp->data['media_id_string'];
cache_set('temp_media_ids_' . $user->uid, ''); //Remove the image after use it
}
return $twitter->statuses_update($status, $param);
}

cloudbull’s picture

and support insert image when unpublish / publish content, the way to pass media id i use is by cache, is there any better approach?

worthy to patch this into twitter module ?

+// implement hook_node_update for auto-sent twitter

+function coconuts_solr_node_update($node) {

+

+ //If publish a content from unpublish

+ if (isset($node->original->status) && $node->original->status == 0 && $node->status == 1){

+

+ if ( $node->field_image['und'][0]['fid'] ) {

+ $file = file_load($node->field_image['und'][0]['fid']); // The image which needs uploading

+ $path = drupal_realpath($file->uri);

+ $handle = fopen($path, "r");

+ $contents = fread($handle, filesize($path));

+ fclose($handle);

+ }

+

+ module_load_include('inc', 'twitter');

+ if ( $node->twitter['account'] )

+ $account = twitter_account_load($node->twitter['account']); // The twitter account name or id

+ if ( $account )

+ $media = twitter_upload_media($account, $file->filename, $file->filemime, $contents);

+

+ global $user;

+ //Set as cache for twitter module to use

+ cache_set('temp_media_ids_' . $user->uid, $media);

+

+ }

+}

Jerenus’s picture

This is a patch to fix the image upload issue. It was build on top of 7.x-5.x-dev. Please help checking. Thanks

Status: Needs review » Needs work

The last submitted patch, 39: Support_media_upload_endpoint-1981472-38.patch, failed testing.

sarathkm’s picture

What I assume is this patches is not necessary if you are trying to implement to post your new content with images. That twitter does automatically based on markup tags for twitter. You can provide the meta information using metatag module. Provide appropriate information and see the magic happen in your twitter feeds as you see in your facebook page feed when you post article when it has Organic Graph information in its meta.
For more information on twitter card markup : Click Me

GuyPaddock’s picture

#27 does not apply cleanly to 7.x-6.x-dev, FYI.

GuyPaddock’s picture

@Jerenus: How is your patch in #39 better / how does it improve upon the patch in #27?

GuyPaddock’s picture

@intrafusion: In #33, why implode(',', $media['media_id'])? The media ID isn't an array, as far as I can tell.

dmsmidt’s picture

Version: 7.x-5.x-dev » 7.x-6.x-dev

@GuyPaddock, I compared 26 and 38, the only functional change is in twitter_set_status(). It adds:

diff --git a/twitter.inc b/twitter.inc
index 52f926c..96e80e0 100644
--- a/twitter.inc
+++ b/twitter.inc
@@ -261,7 +261,16 @@ function twitter_set_status($twitter_account, $status) {
   if (empty($twitter)) {
     return FALSE;
   }
-  return $twitter->statuses_update($status);
+
+  // Support media
+  global $user;
+  $temp = cache_get('temp_media_ids_' . $user->uid);
+  $param = array();
+  if ( $temp ) {// if there is a cache from same user
+    $param['media_ids'] = $temp->data['media_id_string'];
+    cache_set('temp_media_ids_' .  $user->uid, ''); //Remove the image after use it
+  }
+  return $twitter->statuses_update($status, $param);
 }

It seems it is the hacky fix proposed by @cloudbull in #37 and #38 and IMHO should not go in like this.

intrafusion’s picture

@GuyPaddock, it's possible to upload 1-4 images for each tweet, so by making sure it's always an array will handle cases when there is only 1 image as well as multiple.

dmsmidt’s picture

Version: 7.x-6.x-dev » 7.x-5.x-dev
Assigned: Unassigned » dmsmidt

Since there is no upgrade path for 5.x to 6.x I'm working on some improvements of the patch in #26/#27.
Among some coding standards cleanup I'll introduce a hook in the twitter_post module, to more easily provide media to upload with a status update.

dmsmidt’s picture

Assigned: dmsmidt » Unassigned
Status: Needs work » Needs review
FileSize
13.6 KB
12.16 KB

So here is an improved patch, which makes it easier to provide media programatically during a node insert. Just implement hook_twitter_post_node_insert_files (see the new twitter_post.api.php file).

dmsmidt’s picture

Processed IRL review from @stevenbuteneers.

Steven Buteneers’s picture

Status: Needs review » Reviewed & tested by the community
RAFA3L’s picture

Thanks dmsmidt, work perfect after fix this in the twitter.inc file:

line 290
$raw_media = file_get_contents($file['uri']);

line 297
$response = $twitter->media_upload($file['filename'], $file['filemime'], $raw_media);

DamienMcKenna’s picture

Status: Reviewed & tested by the community » Needs work
smustgrave’s picture

Does anyone know if this patch would work for the 7.x-6.x dev version?

oadaeh’s picture

@RAFA3L I think you're using it wrong. $files is supposed to be an array of Drupal file objects.
The comment for the $files parameter for twitter_set_status_with_media() is not very clear on that.

@smustgrave the patch does NOT apply to the 7.x-6.x-dev branch. However, you can try this one I manually created from the one for 7.x-5.x. I have not tested the code, and I really didn't inspect it very closely.
There has been a change to the 7.x-6.x-dev branch that has not yet been applied to the 7.x-5.x-dev, so there are a couple of differences between the two patches for this issue.

oadaeh’s picture

Status: Needs work » Needs review
smustgrave’s picture

@oadaeh Thanks for providing that patch. I tried it out and I get the following errors. I'm trying to test this locally so I'm not sure if that's what's breaking everything. Maybe my local can't communicate with twitter.

Warning: Invalid argument supplied for foreach() in Twitter->call() (line 1403

and

Recoverable fatal error: Argument 1 passed to Entity::__construct() must be of the type array, boolean given, called in C:\Users\Stephen\Documents\devsites\Drupal7\drupal-7.57\sites\all\modules\twitter\twitter.module on line 682 and defined in Entity->__construct() (line 201 of C:\Users\Stephen\Documents\devsites\Drupal7\drupal-7.57\sites\all\modules\entity\includes\entity.inc).
chaloum’s picture

I see this has been in development for 5 years, any idea when this will be in production?

Thanks

oadaeh’s picture

Assigned: Unassigned » oadaeh
Status: Needs review » Active

I'm going to re-roll the patches, due to several patches being recently committed, and see if I can address the error @smustgrave reported.

oadaeh’s picture

Status: Active » Needs review
FileSize
17.28 KB

Sorry for the delay on this. Life got in the way. :)
Here is the re-roll for the 7.x-5.x branch.
I could not create an interdiff, I'm guessing due to some difference in the way the two patches were created, but I could not figure out how to get around that without manually creating the file.
I'll work on updating the 7.x-6.x patch next, but it won't be today. Hopefully, I'll get to it sooner than the 7.x-5.x patch.

oadaeh’s picture

Here is the updated patch for the 7.x-6.x branch.
The interdiff is between this one and the one in #54.
@smustgrave see if this one works better for you.

oadaeh’s picture

Assigned: oadaeh » Unassigned

@chaloum it will only ever go into production when the code works. You can help by reviewing and/or testing it and reporting back what you find. Thanks.

pankajlogical’s picture

@DamienMcKenna Thankyou for you help. I applied patch #49. It did not work but I find idea and change in code to work for me. Again thank you for suggesting me the right direction.

DamienMcKenna’s picture

@pankajxenix: I'm glad you were able to get it working. Would you mind sharing details of what you had to change to make it work? Thanks.

pankajlogical’s picture

@DamienMcKenna I use my image field in twitter_post_node_insert function . Instant of this line $files = module_invoke_all('twitter_post_node_insert_files', $node); I just load my image field here .Thankyou.

nakedscientist’s picture

@oadaeh - I'm on 7x5x branch; I tried your twitter-support_media_upload_endpoint-7x5x-1981472-59.patch - it failed on "3 hunks" - any suggestions?

megthing’s picture

This patch;

https://www.drupal.org/files/issues/support_media_upload_endpoint-7x6x-1...

applied correctly on the 7.x-6.2 version.

I'm using the following value as the message in Rules Action > "Post a message to Twitter"

[node:body] [node:field_image]

But only the [node:body] shows up in the tweet.

jimmynash’s picture

I've tried the patch from #60 against both 7.x-6.2 and 7.x-6.x-dev without any success.

In both cases I get a bunch of offset successes and fuzzes along with some failures.

Here were the results patching against 6x dev:

patch --dry-run -p1 < twitter-support_media_upload_endpoint-7x6x-1981472-60.patch
checking file twitter.inc
checking file twitter.install
checking file twitter.lib.php
Hunk #3 FAILED at 139.
Hunk #4 succeeded at 189 with fuzz 1 (offset 10 lines).
Hunk #5 succeeded at 225 (offset 10 lines).
Hunk #6 succeeded at 256 (offset 10 lines).
Hunk #7 FAILED at 474.
Hunk #8 succeeded at 540 (offset 25 lines).
Hunk #9 succeeded at 1379 (offset 25 lines).
Hunk #10 succeeded at 1419 (offset 25 lines).
2 out of 10 hunks FAILED
checking file twitter.module
checking file twitter.pages.inc
checking file twitter_post/twitter_post.api.php
checking file twitter_post/twitter_post.module
Hunk #1 succeeded at 60 with fuzz 2.

I tried to patch the files manually but it got really stinky in some places and I couldn't figure out where some things were supposed to be.

#66 reports success on 6.2 but I've not been able to get that to work either.

sumitk’s picture

I uploaded my manually patched code here: https://github.com/sumitk/drupal-7-twitter

I didn't create a patch, as I modified it further to make the image upload work with Rules action.

Please use this helper module to identify the correct image field while uploading from node form: https://github.com/sumitk/twitter_image_post