Last active
April 3, 2020 22:33
-
-
Save myklll/2d53a9a5028eedf19462e582c6dcda07 to your computer and use it in GitHub Desktop.
Create a short firebase dynamic link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"github.com/pkg/errors" | |
"google.golang.org/api/firebasedynamiclinks/v1" | |
"google.golang.org/api/option" | |
) | |
func createDynamicLink(l string) (string, error) { | |
ctx := context.Background() | |
firebasedynamiclinksService, err := firebasedynamiclinks.NewService(ctx, option.WithAPIKey("Your API key")) | |
if err != nil { | |
return "", errors.Wrapf(err, "Error creating a firebase dynamic link service: ") | |
} | |
android := &firebasedynamiclinks.AndroidInfo{ | |
AndroidPackageName: "Your android package name", | |
} | |
ios := &firebasedynamiclinks.IosInfo{ | |
IosBundleId: "Your ios bundle identified", | |
IosAppStoreId: "Your appstore id", | |
} | |
nav := &firebasedynamiclinks.NavigationInfo{ | |
EnableForcedRedirect: true, // Disbale preview page | |
} | |
info := &firebasedynamiclinks.DynamicLinkInfo{ | |
DomainUriPrefix: "https://your_subdomain.page.link", | |
AndroidInfo: android, | |
IosInfo: ios, | |
NavigationInfo: nav, | |
Link: l, | |
} | |
req := &firebasedynamiclinks.CreateShortDynamicLinkRequest{ | |
DynamicLinkInfo: info, | |
} | |
link, err := firebasedynamiclinksService.ShortLinks.Create(req).Do() | |
return link.ShortLink, errors.Wrapf(err, "Error creating dynamic link: ") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment