Working locally in a vagrant environment, I've been using ngrok to forward my local development environment and then adding the URL generated by ngrok in the facebook app settings. To make it work, I have to alter the base_url of the canonical url being sent to Facebook to match what facebook expects.

In addition to this, our end user editors work from an alternate domain, different from the production environment, and run into the same issue.

I've added a variable for canonical url so that admins/developers can alter the base url portion of it without hacking the module.

Comments

ryanissamson created an issue. See original summary.

ryan.ryan’s picture

StatusFileSize
new2.41 KB
ryan.ryan’s picture

Status: Active » Needs review

This could probably use validation on the url of the textfield, but will set to needs review.

ryan.ryan’s picture

StatusFileSize
new2.41 KB

Re-rolling the patch against latest dev version.

scottrigby’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Status: Needs review » Needs work

Hey @ryanissamson!

A coupla things:

  1. Hello again!
  2. I just invited you to join the Drupal Instant Articles development FB group - check Facebook :)
  3. Can you add this as a GitHub PR rather than a patch, and we can discuss there? Check out the "Issues and Development" section of the project landing page:
    All development is happening via PRs in GitHub
  4. When you do, please make the PR against 7.x-2.x rather than 7.x-1.x (we're now adding all new features to the 7.x-2.x branch… a release tag from that branch should be coming soon).
  5. Regarding this issue, interestingly I had just done this in a hook rather than building in a config. I'm happy to share that code, but hearing that others besides us may need this, a config sounds like a good new feature.
ryan.ryan’s picture

1. Hey @scottrigby :D Always good to see you.
2. Ah, great, I'll join up there, thanks.
3. Sure, I'll add it through Github, no problem.
4. Cool, good to know, I'll apply to 7.x-2.x and submit.
5. I'd love to see what you did through the hook in case it does work for us. There's a couple other weird things we've got going on, so may or may not work, but would be great if it does.

One additional note, I noticed one thing that needs to be fixed to prevent the absolute url being added to another url. I'll update that. Things just got busy this afternoon, so hope to do it soon.

scottrigby’s picture

Hey :) OK, here is essentially what we had just done:

For 7.x-1.x

hook_fb_instant_articles_display_instant_article_alter(\Facebook\InstantArticles\Elements\InstantArticle $instant_article, $node) {
  if ($canonical_domain = variable_get('fb_instant_articles_canonical_domain')) {
    global $base_path;
    $url = $canonical_domain . $base_path . drupal_get_path_alias('node/' . $node->nid);
    $instant_article->withCanonicalURL($url);
  }
}

For 7.x-2.x

function hook_fb_instant_articles_article_alter($instantArticle, $context) {
  if (isset($context['entity_type']) && isset($context['entity']) && $canonical_domain = variable_get('fb_instant_articles_canonical_domain')) {
    global $base_path;
    $path = entity_uri($context['entity_type'], $context['entity']);
    $url = $canonical_domain . $base_path . drupal_get_path_alias($path);
    $instant_article->withCanonicalURL($url);
  }
}
ryan.ryan’s picture

Thanks for that @scottrigby. That is really helpful.

In the event that it's helpful, I've went ahead and created a PR at: https://github.com/BurdaMagazinOrg/module-fb_instant_articles/pull/72
There's one additional change, which I forgot to take into account, removing the absolute url from the end portion, to prevent malformed urls.

Here's the patch as it stands: https://patch-diff.githubusercontent.com/raw/BurdaMagazinOrg/module-fb_i...

ryan.ryan’s picture

Status: Needs work » Needs review

scottrigby’s picture

Status: Needs review » Fixed

Merged! Nice feature

ryan.ryan’s picture

Thanks Scott!

Also, for anyone else that might be coming from the 7.x-1.x branch, here's a patch for that: https://patch-diff.githubusercontent.com/raw/BurdaMagazinOrg/module-fb_i...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.