Ejemplo n.º 1
0
        public string CreateShareableLink(string path, bool directLink)
        {
            if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo))
            {
                string json = JsonConvert.SerializeObject(new
                {
                    path     = VerifyPath(path),
                    settings = new
                    {
                        requested_visibility = "public" // Anyone who has received the link can access it. No login required.
                    }
                });

                string response = SendRequest(HttpMethod.POST, URLCreateSharedLink, json, ContentTypeJSON, null, GetAuthHeaders());

                if (!string.IsNullOrEmpty(response))
                {
                    DropboxLinkMetadata linkMetadata = JsonConvert.DeserializeObject <DropboxLinkMetadata>(response);

                    if (directLink)
                    {
                        return(GetDirectShareableURL(linkMetadata.url));
                    }
                    else
                    {
                        return(linkMetadata.url);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        public string CreateShareableLink(string path, bool directLink)
        {
            if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo))
            {
                string json = JsonConvert.SerializeObject(new
                {
                    path     = VerifyPath(path),
                    settings = new
                    {
                        requested_visibility = "public" // Anyone who has received the link can access it. No login required.
                    }
                });

                string response = SendRequest(HttpMethod.POST, URLCreateSharedLink, json, ContentTypeJSON, null, GetAuthHeaders());

                DropboxLinkMetadata linkMetadata = null;

                if (!string.IsNullOrEmpty(response))
                {
                    linkMetadata = JsonConvert.DeserializeObject <DropboxLinkMetadata>(response);
                }
                else if (IsError && Errors[Errors.Count - 1].Contains("\"shared_link_already_exists\"")) // Ugly workaround
                {
                    DropboxListSharedLinksResult result = ListSharedLinks(path, true);

                    if (result != null && result.links != null && result.links.Length > 0)
                    {
                        linkMetadata = result.links[0];
                    }
                }

                if (linkMetadata != null)
                {
                    if (directLink)
                    {
                        return(GetDirectShareableURL(linkMetadata.url));
                    }
                    else
                    {
                        return(linkMetadata.url);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public string CreateShareableLink(string path, DropboxURLType urlType)
        {
            if (!string.IsNullOrEmpty(path) && OAuth2Info.CheckOAuth(AuthInfo))
            {
                string json = JsonConvert.SerializeObject(new
                {
                    path     = VerifyPath(path),
                    settings = new
                    {
                        requested_visibility = "public" // Anyone who has received the link can access it. No login required.
                    }
                });

                // TODO: Missing: args.Add("short_url", urlType == DropboxURLType.Shortened ? "true" : "false");

                string response = SendRequestJSON(URLCreateSharedLink, json, GetAuthHeaders());

                if (!string.IsNullOrEmpty(response))
                {
                    DropboxLinkMetadata linkMetadata = JsonConvert.DeserializeObject <DropboxLinkMetadata>(response);

                    if (urlType == DropboxURLType.Direct)
                    {
                        Match match = Regex.Match(linkMetadata.url, @"https?://(?:www\.)?dropbox.com/s/(?<path>\w+/.+)");

                        if (match.Success)
                        {
                            string urlPath = match.Groups["path"].Value;

                            if (!string.IsNullOrEmpty(urlPath))
                            {
                                return(URLHelpers.CombineURL(URLShareDirect, urlPath));
                            }
                        }
                    }
                    else
                    {
                        return(linkMetadata.url);
                    }
                }
            }

            return(null);
        }