发布链接到不显示的页面? [英] Posting a link to a page not showing up?

查看:133
本文介绍了发布链接到不显示的页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <?php 
$ appId ='XXXXX';
$ pageId ='XXXXX';
$ secret ='XXXXX';
$ token ='XXXXX';

$ data = array(
'access_token'=> $ token,
'description'=>'test_description',
'link'=> 'http://www.google.co.uk',
'message'=>'test_message',
'name'=>'test_name'
);

try
{
require_once'facebook / facebook.php';

$ sdk = new Facebook(
array(
'appId'=> $ appId,
'secret'=> $ secret,
'cookie'=> true

);

$ post = $ sdk-> api('/'.$ pageId。'/ feed','POST',$ data);

print_r($ post);
}
catch(FacebookApiException $ e)
{
echo $ e;
}
?>

使用上面的代码,我试图在我的页面墙上发布一个链接到Google。当我运行代码时,我得到一个ID响应,这是我期望的。但是,尽管有一个有效的ID,但是没有任何内容显示在页面上。



如果我删除链接并再次尝试,我会收到另一个ID,我的网页。



我做错了?



为什么链接值会导致ID返回但没有帖子显示?






这是Facebook看到的(通过Graph API资源管理器查询):

  {
id:484729401573953,
created_time:2013-01-08T12 :
caption:www.readesresidential.com,
description:test_description,
from:{
名称:David Reade,
id:100003544363105
},
icon:http://static.ak.fbcdn.net/rsrc.php/ v2 / yD / r / aS8ecmYRys0.gif,
link:http://www.readesresidential.com/brookside-crescent-northop-hall-ch7-6hw-ps03009/,
message:test_message,
name:test_name,
picture:http://external.ak.fbcdn.ne t / safe_image.php?d = AQC7MpbP6aNe2CVP& w = 90& h = 90& url = http%3A%2F%2Fwww.readesresidential.com%2框架%2Fstatic-487d%2F2%2Fimg%2Fv3%2Ffacebook.png,
privacy:{
description:Friends,
value:ALL_FRIENDS,
allow:,
deny :,
networks:,
friends:
}
}

我可以看到它说ALL_FRIENDS - 这可能是导致该帖子不显示的原因吗?你不能成为一个页面的朋友吗?






我现在已将数据变量修改为以下:

  $ data = array(
'access_token'=> $ token,
'description' =''test_description',
'link'=>'http://www.readesresidential.com/go/ps02618',
'message'=>'test_message',
'name'=>'test_name',
'privacy'=> array(
'value'=>'EVERYONE'

);

Graph API资源管理器的响应是:

  {
id:454654274601000,
created_time:2013-01-08T12:14:52 + 0000,
caption:www.readesresidential.com,
description:test_description,
from:{
name:David Reade,
id:100003544363105
},
icon:http://static.ak.fbcdn.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif
link:http://www.readesresidential.com/church-street-tarvin-ch3-8eb-ps02618/,
message:test_message,
名称:test_name,
picture:http://external.ak.fbcdn.net/safe_image.php?d=AQC7MpbP6aNe2CVP&w=90&h=90&url=http%3A% 2F%2Fwww.readesresidential.com%2Fframework%2Fstatic-487d%2F2%2Fimg%2Fv3%2Ffacebook.png,
privacy:{
description:Public,
$
网络:,
朋友:$
}
}

即使该帖子现在是公开的,我使用了一个全新的URL,但仍然没有显示。 / p>

这可能是Facebook的错误吗?

解决方案

代码,我发现如何解决这个问题。尽管调试工具说它是有效的并具有适当的权限,但我使用的访问令牌是不正确的。



我不得不查询Graph API,特定的/ me / accounts位使用访问令牌返回页面信息,但是完全不同的访问令牌。这个访问令牌没有过期时间(我认为这个功能不再是??),并且插入到我的代码之后,现在显示所有用户的帖子。



没有这些步骤在Facebook文档中的任何地方,如果他们是非常难找到。


<?php
$appId  =   'XXXXX';
$pageId =   'XXXXX';
$secret =   'XXXXX';
$token  =   'XXXXX';

$data   =   array(
    'access_token'  => $token,
    'description'   => 'test_description',
    'link'          => 'http://www.google.co.uk',
    'message'       => 'test_message',
    'name'          => 'test_name'
);

try
{
    require_once 'facebook/facebook.php';

    $sdk    =   new Facebook(
        array(
             'appId'    => $appId,
             'secret'   => $secret,
             'cookie'   => true
        )
    );

    $post   =   $sdk->api('/'.$pageId.'/feed', 'POST', $data);

    print_r($post);
}
catch (FacebookApiException $e)
{
    echo $e;
}
?>

Using the code above I am trying to post a link to Google on my page wall. When I run the code, I get an ID response which is what I would expect. However nothing shows up on the page, despite having a valid ID.

If I remove the "link" and try again, I get another ID and the post is visible on my page.

Am I doing something wrong?

Why should the "link" value cause an ID to be returned but no post to be displayed?


This is what Facebook sees (queried via the Graph API explorer):

{
  "id": "484729401573953",
  "created_time": "2013-01-08T12:03:27+0000",
  "caption": "www.readesresidential.com",
  "description": "test_description",
  "from": {
    "name": "David Reade",
    "id": "100003544363105"
  },
  "icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif",
  "link": "http://www.readesresidential.com/brookside-crescent-northop-hall-ch7-6hw-ps03009/",
  "message": "test_message",
  "name": "test_name",
  "picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQC7MpbP6aNe2CVP&w=90&h=90&url=http%3A%2F%2Fwww.readesresidential.com%2Fframework%2Fstatic-487d%2F2%2Fimg%2Fv3%2Ffacebook.png",
  "privacy": {
    "description": "Friends",
    "value": "ALL_FRIENDS",
    "allow": "",
    "deny": "",
    "networks": "",
    "friends": ""
  }
}

I can see it says "ALL_FRIENDS" - could this be what's causing the post to not be displayed? You can't be friends with a page can you?


I have now modified the "data" variable to the following:

$data   =   array(
    'access_token'  => $token,
    'description'   => 'test_description',
    'link'          => 'http://www.readesresidential.com/go/ps02618',
    'message'       => 'test_message',
    'name'          => 'test_name',
    'privacy'       => array(
        'value'   => 'EVERYONE'
    )
);

The response from the Graph API explorer is:

{
  "id": "454654274601000",
  "created_time": "2013-01-08T12:14:52+0000",
  "caption": "www.readesresidential.com",
  "description": "test_description",
  "from": {
    "name": "David Reade",
    "id": "100003544363105"
  },
  "icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif",
  "link": "http://www.readesresidential.com/church-street-tarvin-ch3-8eb-ps02618/",
  "message": "test_message",
  "name": "test_name",
  "picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQC7MpbP6aNe2CVP&w=90&h=90&url=http%3A%2F%2Fwww.readesresidential.com%2Fframework%2Fstatic-487d%2F2%2Fimg%2Fv3%2Ffacebook.png",
  "privacy": {
    "description": "Public",
    "value": "EVERYONE",
    "allow": "",
    "deny": "",
    "networks": "",
    "friends": ""
  }
}

Even though the post is now "public" and I have used a completely new URL, it's still not showing.

Could this be a Facebook bug?

解决方案

After some fiddling with the code, I found out how to fix this. Turns out the access token I was using was incorrect, even though the debugger tool said it was valid and had the appropriate permissions.

I had to query the Graph API, in particular the /me/accounts bit using the access token which returned the page info but and a completely different access token. This access token in question has no expiration time (I thought this feature was no more??) and after inserting it into my code, the posts now display properly for all users.

None of these steps were in the Facebook documentation anywhere, and if they are then they're extremely hard to find.

这篇关于发布链接到不显示的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆