从Facebook API打算图片:我认为一些Array'Key'或者Json Encode是原因 [英] Taging pictures from facebook API : I think some Array 'Key' Or Json Encode Is the cause
问题描述
Array([error] => Array([message] =>(#100)参数无效
[type] => OAuthException [code] => 100))
这是我的代码
$ sqls = mysql_query($ sql);
while($ sqlr = mysql_fetch_array($ sqls,MYSQL_NUM))
{
$ users [] = $ sqlr ['regidfriendsid'];
}
($ t = 0; $ t <3; $ t ++)
{
$ tag [$ t] = array 'tag_uid'=>($ users [$ t]),'x'=>(20 + $ x),'y'=>(85 + $ y));
$ x = $ x + 200;
$ z ++;
if($ z%4 == 0)
{
$ y = $ y + 178;
$ x = 0;
}
}
$ tag = array($ tag [1],$ tag [2],$ tag [3]);
$ tags = json_encode($ tag);
print_r($ tags);
//标签的结束循环
//上传照片
$ file ='styleimage / save_as_this_name.jpg';
$ args = array(
'message'=>'My Stylish friends',
'tags'=> $ tags,
);
print_r($ args);
$ args [basename($ file)] ='@'。真实路径($文件);
$ ch = curl_init();
$ url ='https://graph.facebook.com/me/photos?access_token='.$_SESSION['access_token'];
curl_setopt($ ch,CURLOPT_URL,$ url);
curl_setopt($ ch,CURLOPT_HEADER,false);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ ch,CURLOPT_POST,true);
curl_setopt($ ch,CURLOPT_POSTFIELDS,$ args);
$ data = curl_exec($ ch);
//返回照片ID
print_r(json_decode($ data,true));
OUTPUT
[{tag_uid:100003656759153,x:220,y:85},{tag_uid:100004078326378,x:420,y tag_uid:100000034798548,x:620,y:85}] @@@@@ Array([message] => My Stylish friends [tags] => [{tag_uid 100003656759153\" , ×:220, Y:85},{ tag_uid: 100004078326378, ×:420, Y:85},{ tag_uid: 100000034798548, x 的:620,y:85}])
- 发布标签的实际内容之前。现在尝试发布---
Array([error] => Array([message] =>(#100)无效参数[type] => OAuthException [code] => 100))
问题是x,y坐标您要添加标签。
x和y应该是从左边(对于x)/顶部(对于y)来说是百分比偏移
x和y应在0到100之间。
您可以使用 rand()
函数
x = rand(0,100);
y = rand(0,100);
可能这将帮助您。 :)
I am trying to post a picture on facebook by the graph API ,How ever I am unable to post that. I get this error
Array ( [error] => Array ( [message] => (#100) Invalid parameter [type] => OAuthException [code] => 100 ) )
Here is my Code
$sqls= mysql_query($sql);
while($sqlr = mysql_fetch_array( $sqls, MYSQL_NUM ))
{
$users[]= $sqlr['regidfriendsid'];
}
for ($t=0 ; $t<3;$t++)
{
$tag[$t] = array( 'tag_uid' => ($users[$t]), 'x' => (20+$x), 'y' => (85+$y) );
$x=$x+200;
$z++;
if ($z%4==0)
{
$y=$y+178;
$x=0;
}
}
$tag = array($tag[1], $tag[2], $tag[3]);
$tags = json_encode($tag);
print_r($tags);
// end loop for tags
//upload photo
$file= 'styleimage/save_as_this_name.jpg';
$args = array(
'message' => 'My Stylish friends',
'tags' => $tags,
);
print_r($args);
$args[basename($file)] = '@' . realpath($file);
$ch = curl_init();
$url = 'https://graph.facebook.com/me/photos?access_token='.$_SESSION['access_token'];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
//returns the photo id
print_r(json_decode($data,true));
OUTPUT
[{"tag_uid":"100003656759153","x":220,"y":85},{"tag_uid":"100004078326378","x":420,"y":85},{"tag_uid":"100000034798548","x":620,"y":85}]@@@@@Array ( [message] => My Stylish friends [tags] => [{"tag_uid":"100003656759153","x":220,"y":85},{"tag_uid":"100004078326378","x":420,"y":85},{"tag_uid":"100000034798548","x":620,"y":85}] )
--Before posting the actual content of tags . Now trying to post ---
Array ( [error] => Array ( [message] => (#100) Invalid parameter [type] => OAuthException [code] => 100 ) )
The problem is x,y coordinate where you want to add tags.
x and y should be as a percentage offset from the left ( for x ) / top ( for y ) edge of the picture i.e.
x and y should be in between 0 - 100.
You can use rand()
function
x = rand ( 0, 100 );
y = rand ( 0, 100 );
May be this will help you out. :)
这篇关于从Facebook API打算图片:我认为一些Array'Key'或者Json Encode是原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!