简体   繁体   English

无法将缩略图/图像添加到Facebook应用程序链接

[英]Can't add thumbnail/image to Facebook App link

I've tried to add a thumbnail to the facebook app link, but can't even find documentation about it. 我尝试将缩略图添加到Facebook应用程序链接,但是甚至找不到有关它的文档。 Is it possible? 可能吗? The current code (PHP/Laravel) gives me a working link, which looks like this: https: // fb.me/1234567890. 当前代码(PHP / Laravel)为我提供了一个工作链接,如下所示:https:// fb.me/1234567890。 It writes the app name as well when posted on Facebook, but with no image/thumbnail. 在Facebook上发布时,它也会写应用程序名称,但没有图像/缩略图。 I've tried putting an "image" or "thumbnail" parameter in http_build_query, but with no luck. 我尝试在http_build_query中放置“图像”或“缩略图”参数,但是没有运气。

    $url = "https://graph.facebook.com/v2.6/app/app_link_hosts";
$ch = curl_init($url);

# create form post data
$metadata = "?item=" . $request->itemid;

$deepLinkURL = "APP://" . $metadata;

//echo $deepLinkURL;
$androidArray = json_encode(array(array("url"          => $deepLinkURL,
                                    "package" => "com.app.package",
                                    "app_name"     => "APPNAME")
                              )
                       ); 

$iosArray = json_encode(array(array("url"          => $deepLinkURL,
                                    "app_store_id" => 45345345,
                                    "app_name"     => "APPNAME")
                              )
                       );

$webFallbackArray = json_encode(array("should_fallback" => false));


$formQuery = http_build_query(array("access_token" => "1234567890|XXXXXXXXXXXXXXXX",
                                    "name"         => "APPNAME",
                                    "android"      => $androidArray,
                                    "ios"          => $iosArray,
                                    "thumbnail"        => "http://i.imgur.com/upnywSR.jpg",
                                    "web"          => $webFallbackArray)
                              );

  $path = base_path() . "/vendor/phpunit/phpunit/build/ca.pem"; 

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_CAINFO, $path);

# options
curl_setopt($ch, CURLOPT_POST, true); //1
curl_setopt($ch, CURLOPT_POSTFIELDS, $formQuery);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

# get response

$resultStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$jsonResponse = json_decode(curl_exec($ch), true);
curl_close($ch);



# decode response from facebook

$appLinkId = "";



# get appLinkId
foreach ($jsonResponse as $key => $val) {

    # get status
    if($key == "id") {
        $appLinkId = $val;
    }
}

# if response is good, need to request canonical URL from appLinkId
$errorMessage = "";
$canonicalUrl = "";

if(!empty($appLinkId)) {



    # create another instance of cURL to get the appLink object from facebook using the ID generated by the previous post request
    $getAppLinkUrl = "https://graph.facebook.com/" . $appLinkId;
    $ch2 = curl_init($getAppLinkUrl);

    # cURL options
    $queryString = http_build_query(array("access_token" => "206722406330430|XRV38UNZsFfRNNF1EkfikzDWkpk",
                                          "fields"       => "canonical_url",
                                          "pretty"       => true)
                                    );
/////////////////////
$path = base_path() . "/vendor/phpunit/phpunit/build/ca.pem"; 

curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch2, CURLOPT_CAINFO, $path);
/////////////////


    curl_setopt($ch2, CURLOPT_URL, $getAppLinkUrl . "?" . $queryString);
    curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);

    # get response
  //  $urlResponseJson = curl_exec($ch2);
      $urlJsonResponse = json_decode(curl_exec($ch2), true);
    curl_close($ch2);

    # decode response from facebook


    # parse response to get canonical URL
    foreach ($urlJsonResponse as $key => $val) {
        # get canonical URL
        if($key == "canonical_url") {
            $canonicalUrl = $val;
        }
    }

    # check for result
    if(empty($canonicalUrl)) {
        $errorMessage = "Unable to retreive URL.";
    }

} else {
    $errorMessage = "Unable to publish appLink.";
}

# encode response back to your app
if(empty($errorMessage)) {
    $response = json_encode(array("result"        => "success",
                                  "canonical_url" => $canonicalUrl));
} else {
    $response = json_encode(array("result" => "failed",
                                  "errorMessage" => $errorMessage));
}
return $response;

I've tried to add a thumbnail to the facebook app link, but can't even find documentation about it. 我尝试将缩略图添加到Facebook应用程序链接,但是甚至找不到有关它的文档。 Is it possible? 可能吗?

No. 没有。

As https://developers.facebook.com/docs/applinks/hosting-api says, 正如https://developers.facebook.com/docs/applinks/hosting-api所说,

If your application doesn't have a website for content you want to share to Facebook, you don't have public web URLs which you can annotate to support App Links. 如果您的应用程序没有要共享给Facebook的内容的网站,则您没有公共Web URL,您可以对其进行注释以支持App Links。 For these types of apps, Facebook provides an App Links Hosting API that will host App Links for you. 对于这些类型的应用程序,Facebook提供了一个App Links Hosting API,它将为您托管App Links。

So if you have public web URLs that you want to share, then you should rather annotate those with the meta tags for App Links – then it will take the thumbnail you specified for those URLs via og:image. 因此,如果您有要共享的公共Web URL,则应该使用应用链接的meta标签对其进行注释-然后它将通过og:image为您为这些URL指定的缩略图。

If that is not an option, then you could still try and specify a thumbnail when you share the canonical URL of the App Link object, fe via the Feed dialog. 如果这不是一个选择,那么当您通过Feed对话框共享App Link对象的规范URL时,仍然可以尝试指定缩略图。

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

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