private void PostPhoto()
        {
            Bitmap             image      = BitmapFactory.DecodeResource(Resources, Resource.Drawable.icon);
            SharePhoto         sharePhoto = (SharePhoto) new SharePhoto.Builder().SetBitmap(image).Build();
            IList <SharePhoto> photos     = new List <SharePhoto>();

            photos.Add(sharePhoto);

            SharePhotoContent sharePhotoContent =
                new SharePhotoContent.Builder().SetPhotos(photos).Build();

            if (canPresentShareDialogWithPhotos)
            {
                shareDialog.Show(sharePhotoContent);
            }
            else if (HasPublishPermission())
            {
                ShareApi.Share(sharePhotoContent, shareCallback);
            }
            else
            {
                pendingAction = PendingAction.POST_PHOTO;
                // We need to get new permissions, then complete the action when we get called back.
                LoginManager.Instance.LogInWithPublishPermissions(this, PERMISSION);
            }
        }
Exemplo n.º 2
0
        private void PostPhoto()
        {
            var image      = BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.icon);
            var sharePhoto = new SharePhoto.Builder()
                             .SetBitmap(image).Build().JavaCast <SharePhoto> ();

            var photos = new List <SharePhoto> ();

            photos.Add(sharePhoto);

            var sharePhotoContent = new SharePhotoContent.Builder()
                                    .SetPhotos(photos).Build();

            if (canPresentShareDialogWithPhotos)
            {
                shareDialog.Show(sharePhotoContent);
            }
            else if (HasPublishPermission())
            {
                ShareApi.Share(sharePhotoContent, shareCallback);
            }
            else
            {
                pendingAction = PendingAction.POST_PHOTO;
            }
        }
Exemplo n.º 3
0
 public static object shareToWechat(ShareType type, string title, string description, string linkUrl,
                                    string imageUrl)
 {
     return(new ThunkAction <AppState>((dispatcher, getState) => {
         return ShareApi.FetchImageBytes(imageUrl)
         .Then(imageBytes => {
             var encodeBytes = Convert.ToBase64String(imageBytes);
             if (type == ShareType.friends)
             {
                 WechatPlugin.instance().shareToFriend(title, description, linkUrl, encodeBytes);
             }
             else if (type == ShareType.moments)
             {
                 WechatPlugin.instance().shareToTimeline(title, description, linkUrl, encodeBytes);
             }
         }).Catch(error => {
             if (type == ShareType.friends)
             {
                 WechatPlugin.instance().shareToFriend(title, description, linkUrl, null);
             }
             else if (type == ShareType.moments)
             {
                 WechatPlugin.instance().shareToTimeline(title, description, linkUrl, null);
             }
         });
     }));
 }
Exemplo n.º 4
0
        public async Task <OperationResult> ShareAnswerViaSina(String access, Int32 answerId, String content)
        {
            var api    = new ShareApi();
            var result = await api.ShareAnswerViaSina(access, answerId, content);

            return(result);
        }
        async void RequestSharePhoto(Dictionary <string, object> paramsDictionary)
        {
            if (paramsDictionary != null && paramsDictionary.ContainsKey("photo"))
            {
                var imageBytes             = paramsDictionary["photo"] as byte[];
                SharePhoto.Builder builder = new SharePhoto.Builder();
                if (paramsDictionary.ContainsKey("caption"))
                {
                    builder.SetCaption($"{paramsDictionary["caption"]}");
                }

                Bitmap bmp = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
                //Bitmap mutableBitmap = bmp.copy(Bitmap.Config.ARGB_8888, true);

                SharePhoto sharePhoto = builder.SetBitmap(bmp).Build().JavaCast <SharePhoto>();


                var photos = new List <SharePhoto>();
                photos.Add(sharePhoto);

                var sharePhotoContent = new SharePhotoContent.Builder()
                                        .SetPhotos(photos).Build();

                ShareApi.Share(sharePhotoContent, shareCallback);
            }
        }
Exemplo n.º 6
0
        public async Task <ShareResult> GetAnswerShareTemplate(String access, Int32 answerId,
                                                               Boolean autoCache = false)
        {
            var api    = new ShareApi();
            var result = await api.GetAnswerShareTemplate(access, answerId, autoCache);

            return(result);
        }
Exemplo n.º 7
0
 /// <summary>
 /// 初始化
 /// </summary>
 public YbClient(string token)
 {
     share  = new ShareApi(token);
     friend = new FriendApi(token);
     group  = new GroupApi(token);
     msg    = new MsgApi(token);
     pay    = new PayApi(token);
     school = new SchoolApi(token);
     user   = new UserApi(token);
 }
Exemplo n.º 8
0
 /// <summary>
 /// 初始化
 /// </summary>
 public YbClient(AccessToken token, YbConfig config)
 {
     share  = new ShareApi(token, config);
     friend = new FriendApi(token, config);
     group  = new GroupApi(token, config);
     msg    = new MsgApi(token, config);
     pay    = new PayApi(token, config);
     school = new SchoolApi(token, config);
     user   = new UserApi(token, config);
 }
Exemplo n.º 9
0
 /// <summary>
 /// 可以利用自己实例化的ApiContext方式构造Client,APIContext包括相关配置和accesstoken
 /// 当不想用配置文件中的配置时可通过这种方式更改配置
 /// </summary>
 /// <param name="context"></param>
 public YbClient(ApiContext context)
 {
     Oauther = new OauthApi(context);
     share   = new ShareApi(context);
     friend  = new FriendApi(context);
     group   = new GroupApi(context);
     msg     = new MsgApi(context);
     pay     = new PayApi(context);
     school  = new SchoolApi(context);
     user    = new UserApi(context);
 }
        public Task <bool> PostPhoto(ImageSource image)
        {
            if (tcsPhoto != null)
            {
                tcsPhoto.TrySetResult(false);
                tcsPhoto = null;
            }
            tcsPhoto = new TaskCompletionSource <bool>();

            var token = AccessToken.CurrentAccessToken?.Token;

            if (string.IsNullOrWhiteSpace(token))
            {
                tcsPhoto.TrySetResult(false);
            }
            else
            {
                bool hasRights;
                if (!HasPublishPermission())
                {
                    hasRights = RequestPublishPermissions(new[] { "publish_actions" }).Result;
                }
                else
                {
                    hasRights = true;
                }

                if (hasRights)
                {
                    var handler     = image.GetHandler();
                    var nativeImage = handler.LoadImageAsync(image, Xamarin.Forms.Forms.Context).Result;

                    var sharePhoto = new SharePhoto.Builder().SetBitmap(nativeImage).Build().JavaCast <SharePhoto>();

                    var photos = new List <SharePhoto>();
                    photos.Add(sharePhoto);

                    var sharePhotoContent = new SharePhotoContent.Builder()
                                            .SetPhotos(photos).Build();

                    ShareApi.Share(sharePhotoContent, this);
                }
                else
                {
                    tcsPhoto.TrySetResult(hasRights);
                }
            }
            return(tcsPhoto.Task);
        }
Exemplo n.º 11
0
        protected override void BeginProcessing()
        {
            try
            {
                var shareApi = new ShareApi(Utilities.Configuration);

                var resp = shareApi.Remove(this.GroupId, this.ShareId);

                WriteObject("Share successfully removed ");
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "", ErrorCategory.NotSpecified, null));
            }
        }
Exemplo n.º 12
0
        protected override void BeginProcessing()
        {
            var shareApi = new ShareApi(Utilities.Configuration);

            var share = new Share();

            share.Properties = new ShareProperties()
            {
                SharePrivilege = this.SharePrivilege,
                EditPrivilege  = this.EditPrivilege
            };

            var shareUpdated = shareApi.Update(this.GroupId, this.ShareId, share, depth: 5);

            if (shareUpdated != null)
            {
                WriteObject(shareUpdated);
            }

            return;
        }
        private void PostStatusUpdate()
        {
            var profile = Profile.CurrentProfile;
            ShareLinkContent linkContent = new ShareLinkContent.Builder()
                                           .SetContentTitle("Hello Facebook")
                                           .SetContentDescription("The 'Hello Facebook' sample  showcases simple Facebook integration")
                                           .SetImageUrl(Uri.Parse("http://developers.facebook.com/docs/android"))
                                           .Build();

            if (canPresentShareDialog)
            {
                shareDialog.Show(linkContent);
            }
            else if (profile != null && HasPublishPermission())
            {
                ShareApi.Share(linkContent, shareCallback);
            }
            else
            {
                pendingAction = PendingAction.POST_STATUS_UPDATE;
            }
        }
Exemplo n.º 14
0
        protected override void BeginProcessing()
        {
            try
            {
                var shareApi = new ShareApi(Utilities.Configuration);

                if (!string.IsNullOrEmpty(this.ResourceId))
                {
                    var share = shareApi.FindById(this.GroupId, this.ResourceId, depth: 5);

                    WriteObject(share);
                }
                else
                {
                    var share = shareApi.FindAll(this.GroupId, depth: 5);

                    WriteObject(share.Items);
                }
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "", ErrorCategory.NotSpecified, null));
            }
        }
        async void RequestShare(Dictionary <string, object> paramsDictionary)
        {
            if (paramsDictionary.TryGetValue("content", out object shareContent) && shareContent is FacebookShareContent)
            {
                ShareContent content = null;
                if (shareContent is FacebookShareLinkContent)
                {
                    FacebookShareLinkContent linkContent        = shareContent as FacebookShareLinkContent;
                    ShareLinkContent.Builder linkContentBuilder = new ShareLinkContent.Builder();


                    if (linkContent.Quote != null)
                    {
                        linkContentBuilder.SetQuote(linkContent.Quote);
                    }

                    if (linkContent.ContentLink != null)
                    {
                        linkContentBuilder.SetContentUrl(Android.Net.Uri.Parse(linkContent.ContentLink.AbsoluteUri));
                    }

                    if (!string.IsNullOrEmpty(linkContent.Hashtag))
                    {
                        var shareHashTagBuilder = new ShareHashtag.Builder();
                        shareHashTagBuilder.SetHashtag(linkContent.Hashtag);
                        linkContentBuilder.SetShareHashtag(shareHashTagBuilder.Build().JavaCast <ShareHashtag>());
                    }

                    if (linkContent.PeopleIds != null && linkContent.PeopleIds.Length > 0)
                    {
                        linkContentBuilder.SetPeopleIds(linkContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(linkContent.PlaceId))
                    {
                        linkContentBuilder.SetPlaceId(linkContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(linkContent.Ref))
                    {
                        linkContentBuilder.SetRef(linkContent.Ref);
                    }

                    content = linkContentBuilder.Build();
                }
                else if (shareContent is FacebookSharePhotoContent)
                {
                    FacebookSharePhotoContent photoContent = shareContent as FacebookSharePhotoContent;

                    SharePhotoContent.Builder photoContentBuilder = new SharePhotoContent.Builder();

                    if (photoContent.Photos != null && photoContent.Photos.Length > 0)
                    {
                        foreach (var p in photoContent.Photos)
                        {
                            SharePhoto.Builder photoBuilder = new SharePhoto.Builder();

                            if (!string.IsNullOrEmpty(p.Caption))
                            {
                                photoBuilder.SetCaption(p.Caption);
                            }

                            if (p.ImageUrl != null && !string.IsNullOrEmpty(p.ImageUrl.AbsoluteUri))
                            {
                                photoBuilder.SetImageUrl(Android.Net.Uri.Parse(p.ImageUrl.AbsoluteUri));
                            }

                            if (p.Image != null)
                            {
                                Bitmap bmp = BitmapFactory.DecodeByteArray(p.Image, 0, p.Image.Length);

                                photoBuilder.SetBitmap(bmp);
                            }
                            photoContentBuilder.AddPhoto(photoBuilder.Build().JavaCast <SharePhoto>());
                        }
                    }

                    if (photoContent.ContentLink != null)
                    {
                        photoContentBuilder.SetContentUrl(Android.Net.Uri.Parse(photoContent.ContentLink.AbsoluteUri));
                    }

                    if (!string.IsNullOrEmpty(photoContent.Hashtag))
                    {
                        var shareHashTagBuilder = new ShareHashtag.Builder();
                        shareHashTagBuilder.SetHashtag(photoContent.Hashtag);
                        photoContentBuilder.SetShareHashtag(shareHashTagBuilder.Build().JavaCast <ShareHashtag>());
                    }

                    if (photoContent.PeopleIds != null && photoContent.PeopleIds.Length > 0)
                    {
                        photoContentBuilder.SetPeopleIds(photoContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(photoContent.PlaceId))
                    {
                        photoContentBuilder.SetPlaceId(photoContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(photoContent.Ref))
                    {
                        photoContentBuilder.SetRef(photoContent.Ref);
                    }

                    content = photoContentBuilder.Build();
                }
                else if (shareContent is FacebookShareVideoContent)
                {
                    FacebookShareVideoContent videoContent        = shareContent as FacebookShareVideoContent;
                    ShareVideoContent.Builder videoContentBuilder = new ShareVideoContent.Builder();


                    if (videoContent.PreviewPhoto != null)
                    {
                        SharePhoto.Builder photoBuilder = new SharePhoto.Builder();

                        if (!string.IsNullOrEmpty(videoContent.PreviewPhoto.Caption))
                        {
                            photoBuilder.SetCaption(videoContent.PreviewPhoto.Caption);
                        }

                        if (videoContent.PreviewPhoto.ImageUrl != null && !string.IsNullOrEmpty(videoContent.PreviewPhoto.ImageUrl.AbsoluteUri))
                        {
                            photoBuilder.SetImageUrl(Android.Net.Uri.Parse(videoContent.PreviewPhoto.ImageUrl.AbsoluteUri));
                        }

                        if (videoContent.PreviewPhoto.Image != null)
                        {
                            Bitmap bmp = BitmapFactory.DecodeByteArray(videoContent.PreviewPhoto.Image, 0, videoContent.PreviewPhoto.Image.Length);

                            photoBuilder.SetBitmap(bmp);
                        }
                        videoContentBuilder.SetPreviewPhoto(photoBuilder.Build().JavaCast <SharePhoto>());
                    }

                    if (videoContent.Video != null)
                    {
                        ShareVideo.Builder videoBuilder = new ShareVideo.Builder();

                        if (videoContent.Video.LocalUrl != null)
                        {
                            videoBuilder.SetLocalUrl(Android.Net.Uri.Parse(videoContent.PreviewPhoto.ImageUrl.AbsoluteUri));
                        }

                        videoContentBuilder.SetVideo(videoBuilder.Build().JavaCast <ShareVideo>());
                    }


                    if (videoContent.ContentLink != null)
                    {
                        videoContentBuilder.SetContentUrl(Android.Net.Uri.Parse(videoContent.ContentLink.AbsoluteUri));
                    }

                    if (!string.IsNullOrEmpty(videoContent.Hashtag))
                    {
                        var shareHashTagBuilder = new ShareHashtag.Builder();
                        shareHashTagBuilder.SetHashtag(videoContent.Hashtag);
                        videoContentBuilder.SetShareHashtag(shareHashTagBuilder.Build().JavaCast <ShareHashtag>());
                    }

                    if (videoContent.PeopleIds != null && videoContent.PeopleIds.Length > 0)
                    {
                        videoContentBuilder.SetPeopleIds(videoContent.PeopleIds);
                    }

                    if (!string.IsNullOrEmpty(videoContent.PlaceId))
                    {
                        videoContentBuilder.SetPlaceId(videoContent.PlaceId);
                    }

                    if (!string.IsNullOrEmpty(videoContent.Ref))
                    {
                        videoContentBuilder.SetRef(videoContent.Ref);
                    }

                    content = videoContentBuilder.Build();
                }

                if (content != null)
                {
                    ShareApi.Share(content, shareCallback);
                }
            }
        }
Exemplo n.º 16
0
 public void Init()
 {
     //string token = "e8bfb22a15f055e26afb75629ee42017ea48de54";
     api  = new ShareApi(GlobalConfig.accessToken, GlobalConfig.Webconfig);
     uapi = new UserApi(GlobalConfig.accessToken, GlobalConfig.Webconfig);
 }
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            string title          = Intent.GetStringExtra("Title");
            string description    = Intent.GetStringExtra("Description");
            string imageUrl       = Intent.GetStringExtra("ImageUrl");
            string localImagePath = Intent.GetStringExtra("ImagePath");
            string localVideoPath = Intent.GetStringExtra("VideoPath");
            string link           = Intent.GetStringExtra("Link");

            base.OnCreate(savedInstanceState);

            FacebookSdk.ApplicationId   = Droid.DS.FacebookLogin.FacebookAppId;
            FacebookSdk.ApplicationName = "";
            FacebookSdk.SdkInitialize(ApplicationContext);


            callbackManager = CallbackManagerFactory.Create();
            fbShareCallback = new FacebookCallback <SharerResult>
            {
                HandleSuccess = loginResult =>
                {
                    Toast.MakeText(ApplicationContext, "Your post has been shared successfully.", ToastLength.Long).Show();
                    ShareCompleted(ShareStatus.Success, "Your post has been shared successfully.");
                },
                HandleCancel = () =>
                {
                    Toast.MakeText(ApplicationContext, "Cancelled", ToastLength.Long).Show();
                    ShareCompleted(ShareStatus.Cancelled, "User has cancelled.");
                },
                HandleError = loginError =>
                {
                    Toast.MakeText(ApplicationContext, "Error " + loginError.Message, ToastLength.Long).Show();
                    ShareCompleted(ShareStatus.Error, loginError.Message);
                }
            };
            ShareContent shareContent = null;

            if (!string.IsNullOrWhiteSpace(localImagePath))
            {
                SharePhoto sharePhoto = (SharePhoto) new SharePhoto.Builder()
                                        .SetBitmap(Android.Graphics.BitmapFactory.DecodeFile(localImagePath))
                                        .SetCaption(title)
                                        .Build();
                SharePhotoContent content = new SharePhotoContent.Builder()
                                            .AddPhoto(sharePhoto)
                                            .Build();

                shareContent = content; // new ShareMediaContent.Builder().AddMedium(sharePhoto).Build();
            }

            else if (!string.IsNullOrWhiteSpace(localVideoPath))
            {
                Android.Net.Uri videoFileUri = Android.Net.Uri.FromFile(new Java.IO.File(localVideoPath));
                ShareVideo      shareVideo   = (ShareVideo) new ShareVideo.Builder()
                                               .SetLocalUrl(videoFileUri)
                                               .Build();
                ShareVideoContent content = new ShareVideoContent.Builder()
                                            .SetVideo(shareVideo)
                                            .Build();
                shareContent = content;
            }
            else
            {
                var contentBuilder = new ShareLinkContent.Builder();
                contentBuilder.SetContentTitle(title);
                if (!string.IsNullOrWhiteSpace(description))
                {
                    contentBuilder.SetContentDescription(description);
                }
                if (!string.IsNullOrWhiteSpace(imageUrl))
                {
                    contentBuilder.SetImageUrl(Android.Net.Uri.Parse(imageUrl));
                }
                if (!string.IsNullOrWhiteSpace(link))
                {
                    contentBuilder.SetContentUrl(Android.Net.Uri.Parse(link));
                }
                shareContent = contentBuilder.Build();
            }
            if (ShareDialog.CanShow(shareContent.Class))
            {
                var shareDialog = new ShareDialog(this);
                shareDialog.RegisterCallback(callbackManager, fbShareCallback);
                shareDialog.Show(shareContent, ShareDialog.Mode.Automatic);
                return;
            }
            else
            {
                var FBLoginCallback = new FacebookCallback <LoginResult>
                {
                    HandleSuccess = loginResult =>
                    {
                        ShareApi.Share(shareContent, fbShareCallback);
                    },
                    HandleCancel = () =>
                    {
                        Toast.MakeText(ApplicationContext, "Cancelled", ToastLength.Long).Show();
                        ShareCompleted(ShareStatus.Cancelled, "User has cancelled.");
                    },
                    HandleError = loginError =>
                    {
                        LoginManager.Instance.LogOut();
                        Toast.MakeText(ApplicationContext, "Error " + loginError.Message, ToastLength.Long).Show();
                        ShareCompleted(ShareStatus.Error, loginError.Message);
                    }
                };
                LoginManager.Instance.RegisterCallback(callbackManager, FBLoginCallback);
                LoginManager.Instance.LogInWithPublishPermissions(this, new System.Collections.Generic.List <string>()
                {
                    "publish_actions"
                });
            }
        }