Hi,

My colleague en I are having a hard time figuring out how to include a working reference to an image attached to a node using the FB Stream module. When we hardcode an absolute url to an image publicly available on the world wide web, this thing gets posted on the wall. This makes us believe that nor Facebook, nor the FB Stream module is at fault. We're having a difficult time finding the correct functions to build the correct public path to our image. We're using this code.

$field_items = field_get_items('node', $node, 'field_image');
$path = image_style_url('thumbnail', $field_items[0]['uri']);

...

$params = array(
'access_token' => $node->fb_stream_from_token,
'message' => $node->fb_stream_message,
'link' => $node_url,
'name' => $node->title,
//'description' => $node->teaser, // TODO: how in D7?
'description' => drupal_render(node_view($node, $view_mode = 'teaser')),
//'picture' => file_create_url($node->field_image['und'][0]['uri']),
'picture' => $path . $field_items,
'caption' => variable_get('site_name', ''),
'actions' => json_encode(array(
'name' => t('View More'),
'link' => $node_url,
)),
'method' => 'POST',
);

When we print_r this var using the following code, this is shown.

$myVar = print_r($field_items, true);
drupal_set_message(t('Content posted to Facebook.' . $path .'

'. $myVar . '

'));

Only local images are allowed.

Any help is greatly appreciated!

Regards,
Toon

Comments

toonyngarissvenra’s picture

Hm, it seems the image fails to load. Hopefully this one will work.

Dave Cohen’s picture

It doesn't look like you're getting the right URL for the picture.

Your code says 'picture' => $path . $field_items, but $field_items is an array.

I've struggled to get a URL from an image field, and eventually tried code described in http://www.dave-cohen.com/comment/1000043#comment-1000043, maybe that can help you.

toonyngarissvenra’s picture

Worked like a charm! Thanks, Dave!

Dave Cohen’s picture

Status: Active » Fixed

Great. Others interested should see also #1902062: Publish only custom fields

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Bogd@n’s picture

Hi Toon,

I've come accros your post as this is what I'm trying to do (http://www.drupalforfacebook.org/node/2830)
Can I kindly ask to post your final code to get this done?

Thanks,
Bogdan

sergeypavlenko’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new3.01 KB
new30.54 KB

My mini-solution for add pictures when posting. Which makes patch:

1. Adds a new field to a form of posting "Image" in which you can select a field from which the image is added
2. The selected field is saved, then do not select it again
3. Adds the correct image for the new node

To reply attached a screenshot how the patch, if you have questions or suggestions, always is willing to work.

Dave Cohen’s picture

Status: Needs review » Needs work

This is an interesting patch. Has some limitations, like only selecting the first image of a field that may have several. Still it gives a way to select an image, that may be better than nothing.

Some minor fixes necessary, like LANGUAGE_NONE, not 'und'. '_none' is a little weird, could just use 0 for that.

I'm not sure that calling node_load in the middle of hook_node_insert is a good idea. I hope there's a way to avoid that.

sergeypavlenko’s picture

This is an interesting patch. Has some limitations, like only selecting the first image of a field that may have several. Still it gives a way to select an image, that may be better than nothing.

I had the task at all to send the picture on facebook, therefore there is a feature to send only a single image, in the future it will be possible to finalize the this functionality.

Some minor fixes necessary, like LANGUAGE_NONE, not 'und'. '_none' is a little weird, could just use 0 for that.

You're absolutely right, it is necessary to use LANGUAGE_NONE, but it is not easy to changemust then to take into account other languages. Soon I will lay out an updated patch.

I'm not sure that calling node_load in the middle of hook_node_insert is a good idea. I hope there's a way to avoid that.

The variable $node unfortunately does not contain necessary to me field, and therefore it was necessary to load the a node from scratch, if there is another solution, you can use it.

sergeypavlenko’s picture

Status: Needs work » Needs review
StatusFileSize
new2.26 KB
new3.21 KB

As promised, the patch with the addition of LANGUAGE_NONE and a little corrected code.

'_none' is a little weird, could just use 0 for that.

I think it is better to use _none, so more understandable when reading the code.

Dave Cohen’s picture

Cool, getting better. The weird thing about the node_load is that modules' hook_node_load() will be called before their hook_node_insert(). So while it may work in your case, it could break a site that has different modules installed.

I think the solution would be to use EntityFieldQuery instead.

sergeypavlenko’s picture

Hi

Please be more specific, what we accomplish using the specified class you for searching? As I understand it, this class only searches.

Maybe it makes sense to use - entity_load?

sergeypavlenko’s picture

Think I found the correct way out. To answer a new patch attached. Please see it.

Vishal_123’s picture

Hello sergeypavlenko,

I used your patch in 'Drupal for facebook' module and by using it, i am able to publish the content posted on my site to my facebook wall. But these posts not showing on my friends wall. In order to show them to my all friends wall, i manually have to go with Share option for every post.
What can i do so that it automatically come up on there wall. Normally whenever i post anything on my facebook wall, it automatically comes on my all friends wall.

Some points:
#1 My app. is in Live mode.
#2 Permission in privacy settings are set as public.
Please help me,

Thanks
Vishal

sergeypavlenko’s picture

Hello, @Vishal_123

Please indicate, without my patch publication goes right?

Vishal_123’s picture

Thank you sergeypavlenko, for the replay.

I just tried what you ask.
I removed the patch from the module and than added a new content from my website, this time the content published successfully on my facebook wall without image, but it didn't appeared on my friends wall.
I also tried a simple post directly from facebook and it appears on my all friends wall.

There is an option in this module in - 'Post to Facbook' >> Show Override defaults (advanced), there is a drop down - 'Post to Wall' and i have only one option with my fb account name in it. Is this have any relation from publishing stream to my wall as well as my friends wall ?

Vishal

Gode.Agarunov’s picture

Version: 7.x-3.3-beta6 » 7.x-3.x-dev
StatusFileSize
new3.37 KB

Rerolled for latest dev 10/3/13. Also working on latest 7.x-3.x-beta3.

Original patch by #13 failed at hunk 2, and gave some other warnings. I manually applied missing hunk and tested to make sure it was working properly, and then rerolled for latest dev and 7.x-3.x-beta3 branches (the fb_stream.mod file is the same in both).

Gode.Agarunov’s picture

I created another patch to allow the previous patch from #17 to also work with the media module, allowing media fields to be selected in facebook post (the website I am working on uses media fields for the header image that I need to post to facebook). I tested it and it did post the image to facebook, but I am unsure of what exactly will happen if the uploaded media is not an image. I figured I would put this up anyways to save someone in my position some time, and if they needed it to work with videos or anything else they could edit it farther.

This patch applies all the same changes from #17 and #13 (again, all credit goes to #13 for the original patch), so this patch should be applied on a clean version of latest dev (as of 10/3/13) or 7.x-3.x-beta3.

sergeypavlenko’s picture

Hi, @Gode.Agarunov

Thanks updated my patch. The idea with the addition of "media_generic" is interesting, but need to test posting such content.

For the future. Also, please make a patch for interdiff - https://drupal.org/node/1488712.

Hi, @Vishal_123

I understand what you mean. If I have time, I'll try to check the problem.

Vishal_123’s picture

sergeypavlenko - it would be really great if you could help me. I am new to drupal and stuck badly in this task.
I want to stick to this module since this patch only helped me to post image along with content on my facebook wall.

Thanks
Vishal

Gode.Agarunov’s picture

@Vishal_123

So from what I understand, the problem is that when you use the module to post to facebook, it does not show up on your friends wall, but when you post on facebook yourself, it does (regardless of images)?

If you have a friend in particular who has the allow others to post on my timeline permission on (not exact wording, but similar) you may be able to set the "to" parameter to post on their wall in particular.

I did a lot of research on this, and from what I understand one of two things is true:
a) Because a ton of third party apps used to spam everywhere with posts, the ability for a Graph API post to show up on friends activity feeds has been disabled.
b) Because a ton of third party apps used to spam everywhere with posts, facebook uses a complex algorithm to rank what posts should show up in activity feeds, and posts made through third party applications are penalized.

I believe (a) is true for graph API, which is what this module uses to post.

I believe (b) is true for apps using open graph, because before a live open graph app post can even show up in an activity feed the app needs to go through what appears to be a rigorous submission process, outlined here: https://developers.facebook.com/docs/opengraph/submission-process/
(Keep in mind that this does not apply for this module, as it uses a different API)

Also, I have seen a few (and far between) posts that they making a new app and using the authentication code from the new app allowed their posts to show up on a friends activity feed, but I do not believe they mentioned what API they were using, and if it was open graph it may have been because they didn't have the permission approved for by submission in their first open graph app, and when they made the second one and it was in development mode it allowed the stuff to go through, but again, this is just speculation. So if you want to try making a new app and using the code from that, maybe it will fix your problems, but I don't think so.

I realized all this because I had an issue of my own, when posting a piece of content from a pages wall on my website, the link would always show up in a box with a small thumbnail on the left and some text on the right, whether I used the picture patch in this issue or the OG:meta tags fix in the other patch I made here http://drupal.org/node/2104289 to place a picture, the picture always came out a small thumbnail. But when I grabbed the link and shared it manually through the pages status update form, it showed up as a large picture with the website text summary beneath it (I believe that this is referred to as an "image led" post, and can be generated by open graph apps using the "user-generated" tag.). But I could find no way to make a Graph API post from this module produce the same result, and that is again (I believe), because facebook saw large image app generated posts as spam and taking up a lot of room, and took the option out of Graph API and made it part of open graph with a special tag that you need special permission to use:
https://developers.facebook.com/docs/opengraph/howtos/adding-photos-to-s...

** Keep in mind that all this is based on my research, and I may not have the exact reasons of why certain things are the way there are 100% correct, but I do believe that the things are the way they are **

Vishal_123’s picture

@Gode.Agarunov
Thank you for the reply. I am glad that you took time to research on my stuff.
"If you have a friend in particular who has the allow others to post on my timeline permission on (not exact wording, but similar) you may be able to set the "to" parameter to post on their wall in particular."
- When i post anything from my facebook account, it publishes on my friends wall that means this permission is on.

If it is possible to do this with any Open graph module, i can use it. But i didn't found any such module. If you know any, please send me the link. I searched something with this keyword 'Open graph module', 'Open graph app post' etc.
Here are my simple requirement what i want:
I am working on eCommerce website, so there are lot of products there. Whenever i create a new product it should show on fb wall as well as on my friends wall. The post should include product Name, Price, Code and its Image.

Regards
Vishal

daniel.footman’s picture

Hi Vishal,

When you build the FB APP on developer.facebook. The first access to the app will ask you about privacy setting. "X" APP would like to post to Facebook on behalf of you.

Allow? -> OK

Visibility -> Public | Friends | Custom | Only me <- Select Public.

Also in your Facebook privacy settings make sure it is set to Public.

Hope this helps.

Cheers
Daniel