kreait / laravel-firebase

A Laravel package for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
992 stars 163 forks source link

Cannot Create Dynamic Link #133

Closed paradyo closed 2 years ago

paradyo commented 2 years ago

Hey,

Here is my code. `

    $url = 'https://vienot.page.link';

    Firebase::project('app')->auth();
    try {
        $dynamicLinkInstance = Firebase::dynamicLinks()->createDynamicLink($url);
    } catch (CreateDynamicLink\FailedToCreateDynamicLink $e) {
        echo $e->getMessage(); exit;
    }

` Here is the error:

Invalid Dynamic Link domain: '' or Domain Uri Prefix: ''. Expecting exactly one. Dynamic Link Domain isPresent = false, Domain URI prefix isPresent = false, [https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_parameters]

I dont have any idea. I can use cloud messaging easily but can not use dynamic links.

Everything ready at my Firebase panel by the way.

Is there any example code?

jeromegamez commented 2 years ago

It seems like you haven't configured the dynamic-links domain in https://github.com/kreait/laravel-firebase/blob/main/config/firebase.php#L102 (either directly in the config file or via environment variable).

You need to configure the dynamic-links domain with your https://vienot.page.link/ and use the URL call the createDynamicLink method with the URL you want to shorten.

In your .env file:

FIREBASE_DYNAMIC_LINKS_DEFAULT_DOMAIN=https://vienot.page.link/

In your code:

$url = 'https://the.url/you/want-to-shorten';

try {
    $dynamicLinkInstance = Firebase::dynamicLinks()->createDynamicLink($url);
} catch (CreateDynamicLink\FailedToCreateDynamicLink $e) {
    echo $e->getMessage(); exit;
}
paradyo commented 2 years ago

Oh, it looks great but the problem is still going.

Invalid Dynamic Link domain: '' or Domain Uri Prefix: 'https://vienot.page.link/'. Expecting exactly one. Dynamic Link Domain isPresent = false, Domain URI prefix isPresent = false, [https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_parameters]

I've added .env file like you provided.

Here is the code:

`

    $url = 'https://vienot.app/12342';
    Firebase::project('app')->auth();
    $dynamicLinkInstance = Firebase::dynamicLinks();
    try {
        $link = $dynamicLinkInstance->createDynamicLink($url);
    } catch (CreateDynamicLink\FailedToCreateDynamicLink $e) {
        echo $e->getMessage(); exit;
    }

`

EDIT: I just solved. In .env file i removed the last '/' char. And now I get the expected DynamicLink object. Thanks.

jeromegamez commented 2 years ago

Glad it worked out!