-1

下面的代码标记只有第一个 uid 然后它显示致命错误:未捕获的 OAuthException:(#100)无效参数,我可以使用确切的位置进行标记.. 如下代码 x 和 y 值以像素为单位

$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 );
        }
    }
}
4

1 回答 1

0

有一件事我不明白。

foreach的标签正确吗?并在foreach你通过它再次在一个array?比你encode吗?为什么?

第二个请提供更多细节和代码。

我只能通过这些细节来帮助你。

如果您放置以下代码。

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

你会得到以下结果

// 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}

所以你只需要这样做

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

只需将 t 传递给变量并在那里对其进行编码。

请提供更多代码

于 2012-09-22T13:02:03.460 回答