繁体   English   中英

从url / hyperlink发布Open Graph Story

[英]Publish an Open Graph Story from url / hyperlink

我在Facebook App的Open Graph模块中成功创建了一个故事。

故事是:

“约翰[选中] [巴西]成为MYDOMAIN世界杯足球赛的新世界冠军”

[pick]是动作,[country]是用户选择的国家。 这似乎工作正常。 但下一步让我感到困惑。

我希望在我的网站上通过Facebook登录的访问者点击他们认为将赢得即将到来的世界杯的国家的旗帜。 随后,上述故事发布到他们的时间表。

我不知道如何设置它。 Facebook的开发中心是广泛的,但对于像我这样的PHP新手这个过程的步骤并不是很清楚。

假设我的页面上的标志所代表的超链接需要看起来像这样:

http://mydomain.com/storypublisher.php?&country=“Brazil”&image =“Brazilflag.jpg”等

所以我的问题是:

  • storypublisher.php的正确代码是什么?
  • 我上面提到的网址的正确格式是什么?

我已经阅读了有关'Recipe'等的各种教程,但是当你真正开始发布上述故事时,他们让我感到困惑。

像这样? 根据您对代码部分的需求采用它。 使用Facebook PHP SDK

// 0. We don't need to clear session
require_once realpath(dirname(__FILE__)) . 'facebook.php';

$facebook = new Facebook(array(
    'appId' => '',
    'secret' => '',
));

$fbCurrentUserID = $facebook->getUser();

// 1. If we cant get the user log him in and request permissions This requests combined permissions (basic + post)
if (!$fbCurrentUserID){
    $loginUrl = $facebook->getLoginUrl(array(
        'scope' => 'publish_actions',            
        'redirect_uri' => $current_url, // Replace here
    ));
    $this->abortToUrl($loginUrl);
}

// 2. So we do have a current FB user. Lets try to read data (Maybe he declined perms)
try {
    // 2.a Check if has granted us the perms and post
    $isGranted = $facebook->api(array(
        "method"    => "users.hasAppPermission",
        "ext_perm"  => "publish_actions",
        "uid"       => $fbCurrentUserID,
    ));

    if (!$isGranted){
        $login_url = $facebook->getLoginUrl(array(
            'scope' => 'publish_actions',
            'redirect_uri' => $current_url // Replace here
        ));
        die(header('Location: '. $login_url .''));
    }


    $res = $facebook->api('/me/feed', 'POST', array(
        'link' => '', // Replace and fill with your params
        'name' => '', // Replace and fill with your params
        'message' => '', // Replace and fill with your params
        'description' => '', // Replace and fill with your params
        'picture' => '', // Replace and fill with your params
    ));
} catch (FacebookApiException $e) {
    // 2.b Log any error and retry please

    die(header('Location: /'));
}

到目前为止,使用一个小表格发布到Facebook控制器。 如果传递大量数据,请从$ _GET中选择$ _POST。 然后从控制器获取它们并填写replace here我在代码中留下的注释。 如果你是PHP新手,你将需要进一步的指导。 在我的拙见中,从facebook SDK控制器开始是错误的开始。 好吧,我可能错了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM