Can I TAG someone on Facebook through my app?

Does anyone know if I can tag another user if I know their name on the app? I was told that if I tag someone then when I upload a picture to my Facebook page that it will get posted on their site. I am trying to find a way to get photos on another person’s Facebook page. I know you can use the dialog to do this through Corona but the picture I want to post is saved on the device and I was told I can only post a picture to another Facebook page if the picture is on a website. It’s not so I’m trying to find a way to do this. Anyone know?

Thanks!

I think Facebook’s current behavior when you tag someone is to not put the message on their timeline until they approve it.  Facebook really does not want apps writing to other people’s time lines.

That’s okay because I believe the person with the page can set permissions to allow tags without having to approve each one. I’m trying to do this because a business wants everyone to post pictures to their Facebook page and doing a tag would allow this. So can it be done?

Thanks

I did a little more research reading about tagging and how its done. For the Facebook.request method there is a parameters which I use for the attachment. I am wondering if I can add something like the user I want to tag. I was looking at the Facebook page that is referenced in the docs here and it mentions something like message_tags or with-tags. There are fields. The page can be found at:

https://developers.facebook.com/docs/reference/api/post/

I also found where someone used message_tags to post with using php. So this example may work showing how it was done. I’ll see if I can try it out and see what happens. Anyone know how to add it in the parameters for below?

PHP example:

$facebook = new Facebook(array( 'appId' =\> '127916833975\*\*\*', // masked 'secret' =\> 'a3271136ad68587d8e83171148f93\*\*\*' // masked )); $request\_params = array('message' =\> mb\_convert\_encoding('test posting message', 'UTF-8', 'EUC-JP')); $tags = array( 'id' =\> '100000834278\*\*\*', // masked 'name' =\> 'MY\_FRIENDS\_NAME', // masked 'offset' =\> 0, 'length' =\> 15 // friend name length ); $request\_params['message\_tags'] = $tags; $facebook-\>api('/feed', 'POST', $request\_params);

My current code for posting:

 local attachment = { message = field1.text, source = { baseDir=system.TemporaryDirectory, filename="CameraShot.jpg", type="image", }, } facebook.request( "me/photos", "POST", attachment )

I want to include the message tags as parameters in my code.

Thanks,

Warren

I think Facebook’s current behavior when you tag someone is to not put the message on their timeline until they approve it.  Facebook really does not want apps writing to other people’s time lines.

That’s okay because I believe the person with the page can set permissions to allow tags without having to approve each one. I’m trying to do this because a business wants everyone to post pictures to their Facebook page and doing a tag would allow this. So can it be done?

Thanks

I did a little more research reading about tagging and how its done. For the Facebook.request method there is a parameters which I use for the attachment. I am wondering if I can add something like the user I want to tag. I was looking at the Facebook page that is referenced in the docs here and it mentions something like message_tags or with-tags. There are fields. The page can be found at:

https://developers.facebook.com/docs/reference/api/post/

I also found where someone used message_tags to post with using php. So this example may work showing how it was done. I’ll see if I can try it out and see what happens. Anyone know how to add it in the parameters for below?

PHP example:

$facebook = new Facebook(array( 'appId' =\> '127916833975\*\*\*', // masked 'secret' =\> 'a3271136ad68587d8e83171148f93\*\*\*' // masked )); $request\_params = array('message' =\> mb\_convert\_encoding('test posting message', 'UTF-8', 'EUC-JP')); $tags = array( 'id' =\> '100000834278\*\*\*', // masked 'name' =\> 'MY\_FRIENDS\_NAME', // masked 'offset' =\> 0, 'length' =\> 15 // friend name length ); $request\_params['message\_tags'] = $tags; $facebook-\>api('/feed', 'POST', $request\_params);

My current code for posting:

 local attachment = { message = field1.text, source = { baseDir=system.TemporaryDirectory, filename="CameraShot.jpg", type="image", }, } facebook.request( "me/photos", "POST", attachment )

I want to include the message tags as parameters in my code.

Thanks,

Warren

Hi warrenwsav,

I’m trying to do the same thing - did you ever find a solution?

Ed

I’ve not tried this, but this is the best translation of the PHP to Lua I can do without actually trying it:

local attachment = {     message = field1.text,     source = {         baseDir=system.TemporaryDirectory,         filename="CameraShot.jpg",         type="image",     },    message\_tags = {        'id' = '100000834278\*\*\*', -- masked        'name' = 'MY\_FRIENDS\_NAME', -- masked        'offset' = 0,        'length' = 15 -- friend name length    } }         facebook.request( "me/photos", "POST", attachment )

I don’t know if this works with photos.  There are types of tags like story_tags and such and I don’t know what this API expects but . . .

Hi Rob,

Thanks for the reply… to give you a bit more info, a client of mine wants the functionality that users can post pictures to their Facebook page.

I figured that if I could mention a page, this would be a neat solution, so I’ve been reading the Facebook docs here:

https://developers.facebook.com/docs/opengraph/guides/tagging/#mentions

At the moment I’m trying to just post a message to Facebook that mentions a company.  Here’s my code:

[lua]local facebook = require “facebook”

local fbAppID = FACEBOOK-APP-ID-STRING  

local access_token = “”

local function onLoginSuccess()

facebook.request( “me/feed”, “POST”, {message=“This is a test post mentioning company @[COMPANY-FACEBOOK-PAGE-ID]”} )

end

– facebook listener

local function fbListener( event )

    if event.isError then

        native.showAlert( “Oh No!”, “Something has gone wrong!”, { “OK” } )

    else

        if event.type == “session” then    

            access_token = event.token

            if event.phase == “login” then

                onLoginSuccess()

            elseif event.type == “loginFailed” or event.type == “loginCancelled” then

                native.setActivityIndicator( false)

                native.showAlert( “Oh No!”, “Something has gone wrong!”, { “OK” } )

            end

           

        elseif event.type == “request” then

            native.setActivityIndicator( false )

            native.showAlert( “Success!”, “The message has been posted to your wall.”, { “OK” } )

            

        end

    end

end

local function fbLogin( event )    

    native.setActivityIndicator( true )

    facebook.login( fbAppID, fbListener, { “publish_stream” } )

end

[/lua]

The problem is that at the moment it’s posting to Facebook, but not mentioning the company - instead it shows this:

“This is a test post mentioning company @[COMPANY-FACEBOOK-PAGE-ID]”

ie it posts a long number instead of actually mentioning the Company name and linking to their Facebook page.  I have the following ideas where I might have gone wrong:

i) I’m not using the access_token appropriately.  I’ve basically followed what’s written in the Corona docs (http://docs.coronalabs.com/api/library/facebook/login.html), but I don’t understand whether or not I’ve used the access_token correctly, or whether I’ve just retrieved it and now need to use it (e.g. in facebook.request).

ii) Perhaps I need to “enable both tags and messages capabilities for your action type”, which is what’s suggested in the Facebook docs for when you’re mentioning a friend (although it doesn’t specifically state this for mentioning a page)

iii) Perhaps what I want to achieve isn’t even possible from an Android/iPhone app… I have been suggested this after doing some reading around online, but some of the posts were quite old - I’m not sure they’re relevant anymore

Rob or anyone else, do you reckon you can point me in the right direction?

  1. You are probably using the access token just fine or you would not have gotten it to post.  What you might need is the “publish_actions” permission instead of “publish_stream”, but since you got the message to post, that’s likely not it.

  2. This is likely the case.  I doubt the API call is going to know how to parse @id’s like that, instead they want the ID"s to be tagged passed in as a comma seperated list in a single string:   “12932324234, 12381293887923894, 9389348938” etc.

  3. You should be able to get this to work with mobile apps.

Try this:

local function onLoginSuccess()     facebook.request( "me/feed", "POST", {            message="This is a test post mentioning company",            tags = "COMPANY-FACEBOOK-PAGE-ID",     } ) end

Rob

I will try this tonight. Also, when I include a picture in the post will the picture be posted on my facebook side and the sites I tag?

Warren

Hi warrenwsav,

I’m trying to do the same thing - did you ever find a solution?

Ed

I’ve not tried this, but this is the best translation of the PHP to Lua I can do without actually trying it:

local attachment = {     message = field1.text,     source = {         baseDir=system.TemporaryDirectory,         filename="CameraShot.jpg",         type="image",     },    message\_tags = {        'id' = '100000834278\*\*\*', -- masked        'name' = 'MY\_FRIENDS\_NAME', -- masked        'offset' = 0,        'length' = 15 -- friend name length    } }         facebook.request( "me/photos", "POST", attachment )

I don’t know if this works with photos.  There are types of tags like story_tags and such and I don’t know what this API expects but . . .

Hi Rob,

Thanks for the reply… to give you a bit more info, a client of mine wants the functionality that users can post pictures to their Facebook page.

I figured that if I could mention a page, this would be a neat solution, so I’ve been reading the Facebook docs here:

https://developers.facebook.com/docs/opengraph/guides/tagging/#mentions

At the moment I’m trying to just post a message to Facebook that mentions a company.  Here’s my code:

[lua]local facebook = require “facebook”

local fbAppID = FACEBOOK-APP-ID-STRING  

local access_token = “”

local function onLoginSuccess()

facebook.request( “me/feed”, “POST”, {message=“This is a test post mentioning company @[COMPANY-FACEBOOK-PAGE-ID]”} )

end

– facebook listener

local function fbListener( event )

    if event.isError then

        native.showAlert( “Oh No!”, “Something has gone wrong!”, { “OK” } )

    else

        if event.type == “session” then    

            access_token = event.token

            if event.phase == “login” then

                onLoginSuccess()

            elseif event.type == “loginFailed” or event.type == “loginCancelled” then

                native.setActivityIndicator( false)

                native.showAlert( “Oh No!”, “Something has gone wrong!”, { “OK” } )

            end

           

        elseif event.type == “request” then

            native.setActivityIndicator( false )

            native.showAlert( “Success!”, “The message has been posted to your wall.”, { “OK” } )

            

        end

    end

end

local function fbLogin( event )    

    native.setActivityIndicator( true )

    facebook.login( fbAppID, fbListener, { “publish_stream” } )

end

[/lua]

The problem is that at the moment it’s posting to Facebook, but not mentioning the company - instead it shows this:

“This is a test post mentioning company @[COMPANY-FACEBOOK-PAGE-ID]”

ie it posts a long number instead of actually mentioning the Company name and linking to their Facebook page.  I have the following ideas where I might have gone wrong:

i) I’m not using the access_token appropriately.  I’ve basically followed what’s written in the Corona docs (http://docs.coronalabs.com/api/library/facebook/login.html), but I don’t understand whether or not I’ve used the access_token correctly, or whether I’ve just retrieved it and now need to use it (e.g. in facebook.request).

ii) Perhaps I need to “enable both tags and messages capabilities for your action type”, which is what’s suggested in the Facebook docs for when you’re mentioning a friend (although it doesn’t specifically state this for mentioning a page)

iii) Perhaps what I want to achieve isn’t even possible from an Android/iPhone app… I have been suggested this after doing some reading around online, but some of the posts were quite old - I’m not sure they’re relevant anymore

Rob or anyone else, do you reckon you can point me in the right direction?

  1. You are probably using the access token just fine or you would not have gotten it to post.  What you might need is the “publish_actions” permission instead of “publish_stream”, but since you got the message to post, that’s likely not it.

  2. This is likely the case.  I doubt the API call is going to know how to parse @id’s like that, instead they want the ID"s to be tagged passed in as a comma seperated list in a single string:   “12932324234, 12381293887923894, 9389348938” etc.

  3. You should be able to get this to work with mobile apps.

Try this:

local function onLoginSuccess()     facebook.request( "me/feed", "POST", {            message="This is a test post mentioning company",            tags = "COMPANY-FACEBOOK-PAGE-ID",     } ) end

Rob

I will try this tonight. Also, when I include a picture in the post will the picture be posted on my facebook side and the sites I tag?

Warren

Hi Warrenwsav,
Did you ever get this to work? I’m trying to do this but struggling.
Any suggestions? I couldn’t get Rob’s suggestion above to work using 

tags = "COMPANY-FACEBOOK-PAGE-ID",

I think this is because “You cannot specify this field without also specifying a place.” However, mentioning pages shouldn’t require a place to be specified.

Hi Warrenwsav,
Did you ever get this to work? I’m trying to do this but struggling.
Any suggestions? I couldn’t get Rob’s suggestion above to work using 

tags = "COMPANY-FACEBOOK-PAGE-ID",

I think this is because “You cannot specify this field without also specifying a place.” However, mentioning pages shouldn’t require a place to be specified.