Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

php - Facebook Tagging friends to the picture

Below code tag only first uid then then its shows Fatal error: Uncaught OAuthException: (#100) Invalid parameter and can i use exact location for tagging.. as in below code x and y values are in pixel

$facebook = new Facebook ( array (
        'appId' => FBAPPID,
        'secret' => FBSECRETID 
) );
$facebook->setFileUploadSupport ( true );
if (isset ( $_POST ['image'] ) && isset ( $_POST ['tname'] )) {

    $path_to_image = encrypt::instance ()->decode ( $_POST ['image'] );
    $tags = (array)encrypt::instance ()->decode ( $_POST ['tname'] );
    /*
     * Output
     $tags = array (
            0 => '[{"tag_uid":"100001083191675","x":100,"y":100},{"tag_uid":"100001713817872","x":100,"y":230},{"tag_uid":"100000949945144","x":100,"y":360},{"tag_uid":"100001427144227","x":230,"y":100},{"tag_uid":"100000643504257","x":230,"y":230},{"tag_uid":"100001155130231","x":230,"y":360}]' 
        );
     */

    $args = array (
            'message' => 'Von ',
            'source' => '@' . $path_to_image,
            'access_token' => $this->user->fbtoken 
    )
    ;
    $photo = $facebook->api ( $this->user->data->fbid . '/photos', 'post', $args ); // upload works but not tags

    if (is_array ( $photo ) && ! empty ( $photo ['id'] )) {
        echo 'Photo uploaded. Check it on Graph API Explorer. ID: ' . $photo ['id'];
        foreach ( $tags as $key => $t ) {
            $tagRe = json_encode ( $t );
            $args = array (
                    'tags' => $tagRe,
                    'access_token' => $this->user->fbtoken 
            );
            $facebook->api ( '/' . $photo ['id'] . '/tags', 'post', $args );
        }
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There is one thing i dont get.

You foreach the tags as t right? And in the foreach you pass it again in an array? than you encode it? why?

And the second please provide a bit more details and code.

I can only help you this way with these details.

if you place the folowing code.

foreach ( $tags as $t ) {
       echo "<pre>";
       print_r(json_encode($t));
    }

you will get the following result

// encoded to json
{"tag_uid":"100001701664011","x":100,"y":100}
{"tag_uid":"100001726935992","x":100,"y":230}
{"tag_uid":"100001628449733","x":100,"y":360}
{"tag_uid":"100001286641924","x":230,"y":100}
{"tag_uid":"100001785887853","x":230,"y":230}

so you only need to do this

foreach ( $tags as $t ) {
       $tagRes = json_encode($t);
    }

just pass the t in a variable and encode it there.

Please provide more code


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...