trouble using social plugin to post photo on Facebook

I’m having trouble posting a photo on Facebook using the social plugin. Twitter works fine. Any ideas if I’m doing something wrong or does the plugin currently not support this…?

Here’s a smallish test case (archive attached with main.lua, config.lua, and  build.settings):

local widget = require “widget”

function Obj20EventHandler( event )

  – for testing:

  os.exit()

end

Obj20 = widget.newButton({

  x = 284,

  y = 320,

  width = 14,

  height = 14,

  id = “Obj20”,

  label = “X”,

  font = “LucidaConsole”,

  fontSize = 22,

  strokeColor = { default = {1.0, 1.0, 1.0, 1.0}, over = {0.7, 0.7, 0.7, 1.0} },

  onPress = Obj20EventHandler,

})

function Obj23EventHandler( event )

  – save photo p to both directories:

  display.save( p, { filename=“photo.jpg”, baseDir=system.TemporaryDirectory } )

  display.save( p, { filename=“photo.jpg”, baseDir=system.DocumentsDirectory } )

  

  – test image rects:

  img = display.newImageRect(“photo.jpg”, system.TemporaryDirectory, 80, 80/p.ratio) –  works

  img.x = 75

  img.y = 210

  

  img2 = display.newImageRect(“photo.jpg”, system.DocumentsDirectory, 80, 80/p.ratio) – works

  img2.x = 240

  img2.y = 210

  

  

  – test social plugin:

  if event.target.id == “Obj23” then

    serviceName = “facebook”

  elseif event.target.id == “Obj27” then

    serviceName = “twitter”

  end

  local isAvailable = native.canShowPopup( “social”, serviceName )

  

  if ( isAvailable ) then

  

      local listener = {}

  

      function listener:popup( event )

        Obj26.text = 

          “name: " … event.name…”\n"…

          “type: " … event.type…”\n"…

          “action: " … tostring( event.action )…”\n"…

          "limitReached: " … tostring( event.limitReached )

      end

  

     native.showPopup( “social”,

      {

          service = serviceName,

          message = “Hi there!”,

          listener = listener,

          image = 

          {

              { filename=“photo.jpg”, baseDir=system.TemporaryDirectory }, – twitter just does 1st img

              --{ filename=“photo.jpg”, baseDir=system.DocumentsDirectory } – facebook does neither :frowning:

          },

          url = 

          {

              "http://lillipellilabs.com/queue-alert"

          }

      })

  

  else

  

      native.showAlert(

          “Cannot send " … serviceName … " message.”,

          “Please setup your " … serviceName … " account or check your network connection.”,

          { “OK” } )

  end

end

Obj23 = widget.newButton({

  x = 64,

  y = 320,

  width = 99,

  height = 17,

  id = “Obj23”,

  label = “Facebook”,

  font = “Helvetica Neue”,

  fontSize = 22,

  strokeColor = { default = {0.25, 0.54, 0.87, 1.0}, over = {0.17, 0.37, 0.61, 1.0} },

  onPress = Obj23EventHandler,

})

Obj27 = widget.newButton({

  x = 181,

  y = 320,

  width = 69,

  height = 17,

  id = “Obj27”,

  label = “Twitter”,

  font = “Helvetica Neue”,

  fontSize = 22,

  strokeColor = { default = {0.25, 0.54, 0.87, 1.0}, over = {0.17, 0.37, 0.61, 1.0} },

  onPress = Obj23EventHandler,

})

Obj30_options = {

  text = “img in tmp dir”,

  x = 80,

  y = 280,

  width = 113,

  height = 27,

  align = “center”,

  font = “HelveticaNeue”,

  fontSize = 14,

  align = “center”,

}

Obj30 = display.newText( Obj30_options )

Obj30.id = “Obj30”

Obj31_options = {

  text = “img in doc dir”,

  x = 240,

  y = 280,

  width = 113,

  height = 27,

  align = “center”,

  font = “HelveticaNeue”,

  fontSize = 14,

  align = “center”,

}

Obj31 = display.newText( Obj31_options )

Obj31.id = “Obj31”

Obj26_options = {

  text = “Results”,

  x = 160,

  y = 410,

  width = 287,

  height = 107,

  align = “left”,

  font = “HelveticaNeue”,

  fontSize = 14,

  align = “left”,

}

Obj26 = display.newText( Obj26_options )

Obj26.id = “Obj26”

– capture and display photo:

local function onComplete( e )

if e.completed then

    p = e.target

    p.ratio = p.width/p.height

    p.x = 150

    p.y = 75

    p.width = 100

    p.height = 100/p.ratio

  end

end

if media.hasSource( media.Camera ) then

    media.capturePhoto( { listener=onComplete } )

else

    native.showAlert( “Corona”, “This device does not have a camera.”, { “OK” } )

end

Facebook doesn’t like pre-filled message dialogs. Try commenting out the “message” entry in the options table and see if you have more success.

Good idea and one that had occurred to me as well. I tried it again just now to be sure, but the message doesn’t seem to be the issue. I also removed the URL, just in case, to no effect.

But your reply leads me to believe that the social popup should be working to post an image to Facebook. So I must be doing something stupid.

I realized after posting that this code will be tough to test, since it has to run on an actual device to do anything. But I appreciate any and all ideas!

local widget = require( "widget" ) local function shareMe( event ) native.showPopup( "social", { service = serviceName, message = "Hi there!", listener = listener, image = { { filename="selfie-stick.jpg", baseDir=system.ResourceDirectory }, }, url = { "http://www.coronalabs.com", "http://docs.coronalabs.com" } }) end local shareBtn = widget.newButton({ label = "Share", onRelease = shareMe, }) shareBtn.x = display.contentCenterX shareBtn.y = display.contentCenterY

That worked for me. It posted the image to my Facebook Timeline. The text and the URL’s did not post, just the image, but I believe that’s by Facebook’s design.

This was on my Nexus 9 tablet running Android 6.

Rob

Thanks for looking at this. I’ve just tested this on iOS so far (iPhone 6s). When I get the Facebook popup, it has the message “Say something about this…” and the URL along with some stuff scraped off my web site. But no image. The resulting post is also missing the image.

I’ll try the test case app on android to see if it works.

If you are using iOS we highly recommend the Activity plugin instead of the Social plugin. The Social plugin has the ability to do Twitter and FB directly, but these are old iOS 6 style sharing. We are three OS versions past iOS 6. Apps don’t really use sharing that way any more. The Social plugin on Android brings up a sharing box where you pick where you want to share too. The Activity plugin does this on iOS.

Rob

Okay, I’ll do that.

I had already looked at the documentation (https://docs.coronalabs.com/plugin/CoronaProvider_native_popup_activity/showPopup.html) to try to get this working, but it wasn’t (and isn’t) clear how to connect to Facebook. I see there’s a  “UIActivityTypePostToFacebook” (along with several other activities), but these aren’t used in the code examples (i.e., at the bottom). I expected to see one of the “supported activities” used in the syntax somewhere. I feel like I’m missing something.

Is there a better example somewhere?

It’s one of those things that just works. If the user has FB setup in iOS, you will get an FB button.

Rob

It works! [UPDATE: Still no image for Facebook posts on iPhone]

For future reference: You need to add a require statement and modify build.settings as described here ( use the activity syntax here (https://docs.coronalabs.com/plugin/CoronaProvider_native_popup_activity/showPopup.html#TOC).

Thank you for the help Rob!

Regrettably, I spoke too soon. The Facebook part still doesn’t include the image.

iMessage, Twitter, Email, Reminders, and Add To Notes all work fine with the image. However, on the iPhone, Facebook still doesn’t get the image.

Interestingly, after hitting “Facebook” in the new activity popup, it looks like it loads the same (old) Facebook popup I saw earlier.

This is supposed to work, right? My android phone is dead; I’ll try to test it on that if it wakes up. 

Here’s my (new) code:

local widget = require “widget”

local activity = require( “CoronaProvider.native.popup.activity” )

– fn to handle button press on Obj20

https://docs.coronalabs.com/api/library/widget/newButton.html

– note: this fn must be positioned in the stack above Obj20

function Obj20EventHandler( event )

  – default button event code for Obj20

  – put code here to respond to presses on this button

  – for testing:

  os.exit()

end

Obj20 = widget.newButton({

  x = 284,

  y = 320,

  width = 14,

  height = 14,

  id = “Obj20”,

  label = “X”,

  font = “LucidaConsole”,

  fontSize = 22,

  strokeColor = { default = {1.0, 1.0, 1.0, 1.0}, over = {0.7, 0.7, 0.7, 1.0} },

  onPress = Obj20EventHandler,

})

– fn to handle button press on Obj23

https://docs.coronalabs.com/api/library/widget/newButton.html

– note: this fn must be positioned in the stack above Obj23

function Obj23EventHandler( event )

  – default button event code for Obj23

  – save photo p:

  display.save( p, { filename=“photo.jpg”, baseDir=system.TemporaryDirectory } )

  

  

  – test social plugin:

  if event.target.id == “Obj23” then

    serviceName = “facebook”

  elseif event.target.id == “Obj27” then

    serviceName = “twitter”

  end

  

  

  local popupListener = {}

  function popupListener:popup( event )

    Obj26.text = "name: "…event.name…

      "\ntype: "…event.type…

      "\nactivity: "…tostring(event.activity)…

      "\naction: "…tostring(event.action)

   

   end

  

  local itemsToShare = {

    {

      type = “image”,

      value = { filename=“photo.jpg”, baseDir=system.DocumentsDirectory }

    },

    { type = “url”, value = “http://lillipellilabs.com” },

    { type = “string”, value = “Queue Alert 1.0.3 on the way!” },

  }

  

  local options = { items=itemsToShare, listener=popupListener }

  

  native.showPopup( “activity”, options )

  –

end

Obj23 = widget.newButton({

  x = 47,

  y = 320,

  width = 57,

  height = 18,

  id = “Obj23”,

  label = “Share”,

  font = “Helvetica Neue”,

  fontSize = 22,

  strokeColor = { default = {0.25, 0.54, 0.87, 1.0}, over = {0.17, 0.37, 0.61, 1.0} },

  onPress = Obj23EventHandler,

})

Obj26_options = {

  text = “Results”,

  x = 160,

  y = 410,

  width = 287,

  height = 107,

  align = “left”,

  font = “HelveticaNeue”,

  fontSize = 14,

  align = “left”,

}

Obj26 = display.newText( Obj26_options )

Obj26.id = “Obj26”

– capture and display photo:

local function onComplete( e )

if e.completed then

    p = e.target

    p.ratio = p.width/p.height

    p.x = 150

    p.y = 75

    p.width = 100

    p.height = 100/p.ratio

  end

end

if media.hasSource( media.Camera ) then

    media.capturePhoto( { listener=onComplete } )

else

    native.showAlert( “Corona”, “This device does not have a camera.”, { “OK” } )

end

Okay, I got it to work. Facebook will only take the image if the URL is not included. The string value is ignored (and doesn’t matter). But once I removed the URL from “itemsToShare”, the Facebook post included the image (using the activity plugin as described above).

Thanks again for the help!

Hi prof.j.carlson,

I got the same problem and want to say thank you for your information helping me to get through.

Best

Vincent