无法让新的AppLinks在iOS或Android上运行 [英] Cannot get the new AppLinks to work on iOS or Android

查看:178
本文介绍了无法让新的AppLinks在iOS或Android上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最新更新以下更新#5



我正在尝试为我的iOS和Android应用程序实现AppLinks:



使用



我的应用只是真正的移动设备,我误解了AppLinks的工作原理。我以为我可以把 al_ios _ * 元标签放在单一的通用网页上,但这是错误的。对于我网站上的每一个内容都需要一个单独的页面,并且每个页面都需要有自己的AppLinks元标记,以将该特定内容的URL发送回我的应用程序。



当我做错了,当我点击了我的OpenGraph故事在Facebook,它会打开我的网站在网络浏览器,在底部的工具栏上有一个动作图标,我可以点击和可以选择打开我的应用程序。或者我将在OpenGraph故事中精确点击我的应用程序的名称。任何一个快速切换到我的应用程序,但该URL不会特定于我想要我的应用程序导航到的内容。此外,这两个选项都可以,我只想点击故事的任何地方,直接进入我的应用程序,这就是为什么我们都在这里。



解决方案



我将使用共享对话框中的OpenGraph故事为例。



首先,您需要在服务器上创建托管应用程序链接而不是应用程序。在创建OpenGraph故事或任何共享内容之前,请致电您的服务器以完成2事情:



1))创建一个API调用来创建一个新的Facebook应用程序链接,这将提供一个ID



2。)使用该ID进行第二次API调用以获取托管的应用程序链接的URL



这必须在服务器上完成,因为这些API调用需要应用访问令牌,而不是用户访问令牌。此令牌具有应用级权限,而不是用户级权限。您不能也不应该将您的Facebook应用程序秘密存储在您的移动应用程序中,因为有人可以反编译您的应用程序并更改您的Facebook应用程序。不好。使用您的服务器,因为它可以安全地了解您的应用程序的秘密。



我的服务器端在PHP中,所以这里是一个如何完成这个的例子。处理API不是一个特别愉快的经历,所以我希望能够帮助别人格式化请求:

 #使用cURL创建一个新的Facebook应用程序链接
$ metadata =< AppDelegate应用程序中要处理的内容:openURL:sourceApplication:annotation> ;;
$ url =https://graph.facebook.com/v2.1/app/app_link_hosts;
$ ch = curl_init($ url);

#create form post data
$ deepLinkURL =< myApp>://。 $元数据;
$ iosArray = json_encode(array(array(url=> $ deepLinkURL,
app_store_id=>< appStoreId(number)>
app_name=> ;< myAppName>)

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

$ formQuery = http_build_query(array(access_token=>< appId> |< appSecret>,
name=> $ metadata,
ios=> $ iosArray,
web=> $ webFallbackArray)
);

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

#get response
$ responseJson = curl_exec($ ch);
curl_close($ ch);

#解码响应从Facebook
$ jsonResponse = json_decode($ responseJson,true);
$ appLinkId =;

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

#获取状态
if($ key == id){
$ appLinkId = $ val;
}
}

#如果响应不错,需要从appLinkId请求规范的URL
$ errorMessage =;
$ canonicalUrl =;

if(!empty($ appLinkId)){

#创建cURL的另一个实例,使用上一个帖子请求生成的ID从Facebook获取appLink对象
$ getAppLinkUrl =https://graph.facebook.com/。 $ appLinkId;
$ ch2 = curl_init();

#cURL options
$ queryString = http_build_query(array(access_token=>< appId> |< appSecret>,
fields=> canonical_url,
pretty=> true)
);
curl_setopt($ ch2,CURLOPT_URL,$ getAppLinkUrl。?。$ queryString);
curl_setopt($ ch2,CURLOPT_RETURNTRANSFER,true);

#get response
$ urlResponseJson = curl_exec($ ch2);
curl_close($ ch2);

#从...的$解码响应
$ urlJsonResponse = json_decode($ urlResponseJson,true);

#parse response获取规范URL
foreach($ urlJsonResponse as $ key => $ val){
#获取规范URL
if($ key = =canonical_url){
$ canonicalUrl = $ val;
}
}

#检查结果
如果(空($ canonicalUrl)){
$ errorMessage =无法检索URL。
}

} else {
$ errorMessage =无法发布appLink。
}

#编码响应回到你的应用程序
if(empty($ errorMessage)){
$ response = json_encode(array(result=> success,
canonical_url=> $ canonicalUrl));
} else {
$ response = json_encode(array(result=>failed,
errorMessage=> $ errorMessage));
}

#send回应您的应用

返回在您的应用程序中,一旦您确认了一个良好的响应,请将您返回的规范网址作为 url 参数在中[FBGraphObject openGraphObjectForPostWithType:以下。现在当您在Facebook应用程序中点击您的故事时,它将直接转到您的应用程序。没有网页废话。

  //创建一个动作
id< FBOpenGraphAction> action =(id< FBOpenGraphAction>)[FBGraphObject graphObject];

//创建一个对象
id< FBGraphObject>目的;

// set shareDialog参数
FBOpenGraphActionParams * params = [[FBOpenGraphActionParams alloc] init];
params.action = action;
params.actionType = @< myApp>:< myAction>;
params.previewPropertyName = @< key>;
object = [FBGraphObject openGraphObjectForPostWithType:@< myApp>:< myObject>
标题:< title>
image:< urlToPic>
url:< fb.me/xyz规范网址>
描述:< someDescription>];

[action setObject:object forKey:@< key>];

等...


Latest Update Below at Update #5

I'm trying to implement AppLinks for BOTH my iOS AND Android apps : http://applinks.org

I've done the following:

  1. setup a custom url scheme for my app: inacho://
  2. Setup in my App Delegate: - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
  3. Add meta tags to my website at http://www.nachorater.com :

<meta property="al:ios:app_store_id" content="581815579"/>
<meta property="al:ios:app_name" content="iNacho" />
<meta property="al:ios:url" content="inacho://default" />

I've verified that the url scheme works great by typing in a link like inacho://default into Notes and clicking the link it creates. Wa-la! It opens my app.

But when I try clicking on a link to www.nachorater.com from Facebook or Quip, neither app automatically seems to take any notice that the site has these app links setup and it just loads the website in their browser(s) instead of trying to open my app.

Has anyone got this working?

Update:

I had an issue with some meta tags not being in the < head > portion of my templates and I fixed it.

Now the link: http://www.nachorater.com from the iOS Facebook app adds a nice little popup that lets you open the url in the iNacho app like so:

But my links to my dynamic reviews do not seem to be working, yet the Debug app that Ming pointed out shows that the meta tags look correct for them.

For example, http://www.nachorater.com/getReview?reviewID=6396169718595584

meta tags when debugging with https://developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fwww.nachorater.com%2FgetReview%3FreviewID%3D6396169718595584 :

Update #2:

I posted a new nacho review link to my iNacho Facebook timeline and then tried to click on it from the Facebook Mobile app.

It started to load the page and popped up the handy indicator that lets you open the app in iNacho but then once the page loaded, the indicator went away (before I could click it).

Update #3:

From the Facebook app, I can now trigger an inacho URL for my reviews BUT it's ONLY if I click the little popup to open in iNacho before it disappears. If I let the page completely load in Facebook's built-in web view, the little popup disappears still.

Is this a problem with Applinks? Or a problem with the Facebook app? Or by design and why?

Update #4:

I may know what the problem is. The review page in turn loads up a dynamic image for the nacho review. So by loading the page, it has an img src tag that points to a dynamic url that loads the image. Is this being mistaken for a 'redirect' action of some sort?

Example of img tag (rendered): <img width="300" src="/getReviewImage?imageID=6125868501958656"></img>

Note: There are a bunch of other scripts/ajax that gets loaded dynamically too though (Facebook and twitter widgets and the like).

Is this a bug in AppLinks or the Facebook Mobile app? Shouldn't it not care about background loading objects like ajax and dynamic images?

Update #5

7/15/14 - This is still happening with latest Facebook app. When I click a link from my iNacho Facebook page to my iNacho website, it pops up the option to open it in the app for a split second before the page finishes loading. Then it hides it.

As for the twitter app, it does not even give me the popup for a split second. It doesn't seem to recognize the link is appslink enabled at all.

Quip on the other hand, I pasted a nacho link in and the first time I clicked on it, it went to its built-in safari with no option to open in my app. BUT the second time I clicked it, it directly opened my app instead.

Summary: So far, it seems like maybe some apps are implementing the AppLinks Navigation portion incorrectly or something. Quip seems to work but even Facebook's own app seems like it's not working.

解决方案

I was having the same problem with AppLinks and decided to just forego them altogether and just use facebook's app link host: https://developers.facebook.com/docs/applinks/hosting-api

My app is really mobile only, and I misunderstood how AppLinks worked at first. I thought I could just put the al_ios_* meta tags on a single, universal web page but this is wrong. There would need to be a separate page for every piece of content on my site, and each one of those pages needs to have its own AppLinks meta tags to send a URL for that specific content back to my app.

When I was doing it wrong, when I tapped on my OpenGraph story in facebook, it would open my site in the web browser and there was an action icon in the bottom toolbar that I could tap and have the option to open my app. Or I would have to precision-tap the name of my app in the OpenGraph story. Either of those fast-switch to my app, but the URL would not be specific to the content I want my app to navigate to. Also, both of those options suck -- I just want to tap anywhere on the story and go straight to my app, which is why we're all here.

The solution

I am going to use an OpenGraph story with the share dialog as an example.

First, you need to create a hosted app link on your server, not in the app. Before creating your OpenGraph story or whatever is being shared, make a call to your server to accomplish 2 things:

1.) Make an API call to create a new facebook app link, which will give you back an ID

2.) Use that ID to make a 2nd API call to get the URL to your hosted app link

This has to be done on the server because these API calls require an app access token, not a user access token. This token has app level permissions, not user level permissions. You cannot and should not store your facebook app secret anywhere in your mobile application because someone could decompile your app and make changes to your facebook app. No good. Use your server because it can safely know your app secret.

My server side is in PHP so here is an example of how to accomplish this. Dealing with the API wasn't a particularly pleasant experience, so I'll share in hopes that it helps someone else with formatting the requests:

# create a new facebook app link using cURL
$metadata = <what to handle in AppDelegate application:openURL:sourceApplication:annotation>;
$url = "https://graph.facebook.com/v2.1/app/app_link_hosts";
$ch = curl_init($url);

# create form post data
$deepLinkURL = "<myApp>://" . $metadata;
$iosArray = json_encode(array(array("url"          => $deepLinkURL,
                                    "app_store_id" => <appStoreId (number)>,
                                    "app_name"     => "<myAppName>")
                              )
                       );
$webFallbackArray = json_encode(array("should_fallback" => false));

$formQuery = http_build_query(array("access_token" => "<appId>|<appSecret>",
                                    "name"         => $metadata,
                                    "ios"          => $iosArray,
                                    "web"          => $webFallbackArray)
                              );

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

# get response
$responseJson = curl_exec($ch);
curl_close($ch);

# decode response from facebook
$jsonResponse = json_decode($responseJson, true);
$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();

    # cURL options
    $queryString = http_build_query(array("access_token" => "<appId>|<appSecret>",
                                          "fields"       => "canonical_url",
                                          "pretty"       => true)
                                    );
    curl_setopt($ch2, CURLOPT_URL, $getAppLinkUrl . "?" . $queryString);
    curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);

    # get response
    $urlResponseJson = curl_exec($ch2);
    curl_close($ch2);

    # decode response from facebook
    $urlJsonResponse = json_decode($urlResponseJson, true);

    # 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));
}

#send response back to your app

Back in your app, once you confirm a good response, put the canonical URL you get back as the url parameter in [FBGraphObject openGraphObjectForPostWithType: below. Now when you click on your story in the facebook app, it will go straight to your app. No web nonsense.

// Create an action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];

// Create an object
id<FBGraphObject> object;

// set shareDialog parameters
FBOpenGraphActionParams *params = [[FBOpenGraphActionParams alloc] init];
params.action = action;
params.actionType = @"<myApp>:<myAction>";
params.previewPropertyName = @"<key>";
object = [FBGraphObject openGraphObjectForPostWithType:@"<myApp>:<myObject>"
                                                 title:<title>
                                                 image:<urlToPic>
                                                   url:<fb.me/xyz canonical URL>
                                           description:<someDescription>];

[action setObject:object forKey:@"<key>"];

etc...

这篇关于无法让新的AppLinks在iOS或Android上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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