Social providers integration in Xamarin.Android - facebook

I just trying to add add the Facebook integration with my app in Xamarin.Android. For that I found that there is a Component named as Xamarin.Social then I am trying that. Here is my attempt.
Attempt :-
void btnShare_Click(object sender, EventArgs e)
{
try
{
var facebook = new Xamarin.Social.Services.FacebookService()
{
ClientId = AppId,
RedirectUrl = new System.Uri("http://www.facebook.com/connect/login_success.html")
};
// 2. Create an item to share
var item = new Item { Text = "Xamarin.Social is the bomb.com." };
var shareController = facebook.GetShareUI(this, item, result =>
{
if (result.HasFlag(Xamarin.Social.ShareResult.Done))
{
Toast.MakeText(this, "Posted", ToastLength.Long).Show();
}
if (result.HasFlag(Xamarin.Social.ShareResult.Cancelled))
{
Toast.MakeText(this, "Cancelled", ToastLength.Long).Show();
}
});
StartActivity(shareController);
}
catch (Exception exp)
{
}
}
Note :- Facebook login page is opening successfully.
Error :- But I am getting this Forbidded(403) error. the point is this error is not reaching to catch block , but it is shown in a toast notification. so no further details are available.
Does anybody explored this component successfully ?
Any help is appreciated :)

As I mentioned in the comments, I had to many issues using the social plugin, I just used the android share intent, see example below
var shareIntent = new Intent();
shareIntent.SetAction(Intent.ActionSend);
shareIntent.PutExtra(Intent.ExtraText, message); //message is the text you want to share
shareIntent.SetType("text/plain");
StartActivity(shareIntent);

Related

Sharing screenshot with text to facebook unity

I'm trying to give the user the possibility to post a screenshot of his game on facebook with the dowload link of the game.
I've looked a bit and it seemed it would be possible with FB.API, but I can't manage to make it work.
Aparently you need a permission but I can't to find which permission and how to give it.
I'm using unity 2020.3.21f1
Here is what I'm doing for now
public void ShareScreenShot(Texture2D screenShot)
{
byte[] encodedScreenShot = screenShot.EncodeToPNG();
var wwwForm = new WWWForm();
wwwForm.AddBinaryData("image", encodedScreenShot, "ScreenShot.png");
wwwForm.AddField("message", "Venez me défier : https://randomlink.blablabla");
FB.API("me/photos", HttpMethod.POST, ShareScreenShotCallback, wwwForm);
}
void ShareScreenShotCallback(IResult result)
{
if (result.Error != null)
{
Debug.Log(result.Error);
}
else
{
Debug.Log("sharing success");
}
}
If anyone of you knows how it can be done, it would be of great help, thanks
I suppose you need to login to facebook with custom permissions, because the default one only allows you to send invitations to choosen friends.
https://developers.facebook.com/docs/unity/reference/current/FB.LogInWithPublishPermissions/

AEM Workflow custom input data

I need to create a workflow in AEM that for a page (specified as payload) finds all the assets used on the page and uploads a list of them to an external service. So far I have most of the code ready, but business process requires me to use a special code for each of the pages (different for each run of the workflow), so that the list is uploaded to correct place.
That is when I have a question - Can you somehow add more input values for an AEM workflow? Maybe by extending the starting dialog, or adding some special step that takes user input? I need to be able to somehow specify the code when launching the workflow or during its runtime.
I have read a lot of documentation but as this is my first time using workflows, I might be missing something really obvious. I will be grateful for any piece of advice, including a link to a relevant piece of docs.
Yes, that is possible. You need to implement a dialog step in your workflow: https://docs.adobe.com/content/help/en/experience-manager-64/developing/extending-aem/extending-workflows/workflows-step-ref.html#dialog-participant-step
You could:
Create a custom menu entry somewhere in AEM (e.g. Page Editor, /apps/wcm/core/content/editor/_jcr_content/content/items/content/header/items/headerbar/items/pageinfopopover/items/list/items/<my-action>, see under libs for examples)
Create a client-library with the categories="[cq.authoring.editor]". So it is loaded as part of the page editor (and not inside the iframe with your page)
Create a JS-Listener, that opens a dialog if the menu-entry was clicked (see code). You can either use plain Coral UI dialogs, or my example misused a Granite page dialog (Granite reads the data-structure in cq:dialog, and creates a Coral UI component edit-dialog out of it - while Coral is the plain JS UI-framework)
Create a Java-Servlet, that catches your request, and creates the workflow. You could theoretically use the AEM servlet. But I often have to write my own, because it lacks some features.
Here is the JS Listener:
/*global Granite,jQuery,document,window */
(function ($, ns, channel, window) {
"use strict";
var START_WORKFLOW_ACTIVATOR_SELECTOR = ".js-editor-myexample-activator";
function onSuccess() {
ns.ui.helpers.notify({
heading: "Example Workflow",
content: "successfully started",
type: ns.ui.helpers.NOTIFICATION_TYPES.SUCCESS
});
}
function onSubmitFail(event, jqXHR) {
var errorMsg = Granite.I18n.getVar($(jqXHR.responseText).find("#Message").html());
ns.ui.helpers.notify({
heading: "Example Workflow",
content: errorMsg,
type: ns.ui.helpers.NOTIFICATION_TYPES.ERROR
});
}
function onReady() {
// add selector for special servlet to form action-url
var $form = ns.DialogFrame.currentFloatingDialog.find("form");
var action = $form.attr("action");
if (action) {
$form.attr("action", action + ".myexample-selector.html");
}
// register dialog-fail event, to show a relevant error message
$(document).on("dialog-fail", onSubmitFail);
// init your dialog here ...
}
function onClose() {
$(document).off("dialog-fail", onSubmitFail);
}
// Listen for the tap on the 'myexample' activator
channel.on("click", START_WORKFLOW_ACTIVATOR_SELECTOR, function () {
var activator = $(this);
// this is a dirty trick, to use a Granite dialog directly (point to data-structure like in cq:dialog)
var dialogUrl = Granite.HTTP.externalize("/apps/...." + Granite.author.ContentFrame.getContentPath());
var dlg = new ns.ui.Dialog({
getConfig: function () {
return {
src: dialogUrl,
loadingMode: "auto",
layout: "auto"
}
},
getRequestData: function () {
return {};
},
"onSuccess": onSuccess,
"onReady": onReady,
"onClose": onClose
});
ns.DialogFrame.openDialog(dlg);
});
}(jQuery, Granite.author, jQuery(document), window));
And here is the servlet
#Component(service = Servlet.class,
property = {
SLING_SERVLET_RESOURCE_TYPES + "=cq:Page",
SLING_SERVLET_SELECTORS + "=myexample-selector",
SLING_SERVLET_METHODS + "=POST",
SLING_SERVLET_EXTENSIONS + "=html"
})
public class RequestExampleWorkflowServlet extends SlingAllMethodsServlet {
#Override
protected void doPost(#Nonnull SlingHttpServletRequest request, #Nonnull SlingHttpServletResponse response) throws IOException {
final Page page = request.getResource().adaptTo(Page.class);
if (page != null) {
Map<String, Object> wfMetaData = new HashMap<>();
wfMetaData.put("workflowTitle", "Request Translation for " + page.getTitle());
wfMetaData.put("something", "Hello World");
try {
WorkflowSession wfSession = request.getResourceResolver().adaptTo(WorkflowSession.class);
if (wfSession != null) {
WorkflowModel wfModel = wfSession.getModel("/var/workflow/models/example-workflow");
WorkflowData wfData = wfSession.newWorkflowData(PayloadInfo.PAYLOAD_TYPE.JCR_PATH.name(), page.getPath());
wfSession.startWorkflow(wfModel, wfData, wfMetaData);
MyServletUtil.respondSlingStyleHtml(response, HttpServletResponse.SC_OK, "Triggered Example Workflow");
} else {
throw new WorkflowException("Cannot retrieve WorkflowSession");
}
} catch (WorkflowException e) {
MyServletUtil.respondSlingStyleHtml(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
}
} else {
MyServletUtil.respondSlingStyleHtml(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal error - cannot get page");
}
}
}

Preview is not available in sharing to Facebook with Firebase Dynamic Link

I have created a shorten dynamic link with Firebase. When I share the link to Facebook, the preview is not available. I have tried with the long link. It's not working either. I have provided the link with metadata. But is is not showing the preview.
This is the code I am using now.
FirebaseDynamicLinks.getInstance().createDynamicLink()
.setLongLink(Uri.parse(longLink))
.setIosParameters(new DynamicLink.IosParameters.Builder(getPackageName()).build())
.setAndroidParameters(new DynamicLink.AndroidParameters.Builder(getPackageName()).build())
.setSocialMetaTagParameters(
new DynamicLink.SocialMetaTagParameters.Builder()
.setImageUrl(Uri.parse(demoPhoto))
.setImageUrl(Uri.parse(itemsVO.getThumbnail().get(0)))
.build())
.buildShortDynamicLink(ShortDynamicLink.Suffix.SHORT)
.addOnCompleteListener(this, task -> {
if (task.isSuccessful()) {
// Short link created
Uri shortLink = task.getResult().getShortLink();
itemsVO.setShareLink(shortLink.toString()+"?d=1");
shareBtn.setVisibility(View.VISIBLE);
} else {
// Error
Toast.makeText(this, "Error in creating dynamic link", Toast.LENGTH_LONG).show();
// ...
shareBtn.setVisibility(View.GONE);
}
});
Can anyone tell me why it is not working?

Facebook OAuth Xamarin Forms Redirection

I am using xamarin forms OAuth2 to signin into Facebook, Google and Twitter.
On android it works. But on iOS it screen freezes with spinning activity indicator at top right corner. Is there any one having same issue ?.
Update: Please find below code
partial void UIButton15_TouchUpInside(UIButton sender)
{
// https://developers.facebook.com/apps/
var auth = new OAuth2Authenticator(
clientId: "ID",
scope: "",
authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"),
redirectUrl: new Uri("http://www.facebook.com/connect/login_success.html"));
var ui = auth.GetUI();
auth.Completed += FacebookAuth_Completed;
PresentViewController(ui, true, null);
}
async void FacebookAuth_Completed(object sender, AuthenticatorCompletedEventArgs e)
{
if (e.IsAuthenticated)
{
var request = new OAuth2Request(
"GET",
new Uri("https://graph.facebook.com/me?fields=name,picture,cover,birthday"),
null,
e.Account);
var fbResponse = await request.GetResponseAsync();
var fbUser = JsonValue.Parse(fbResponse.GetResponseText());
var name = fbUser["name"];
var id = fbUser["id"];
var picture = fbUser["picture"]["data"]["url"];
var cover = fbUser["cover"]["source"];
}
DismissViewController(true, null);
}
On facebook developer site:
Created app using Facebook login plugin.
Added redirect URL as http://www.facebook.com/connect/login_success.html
UPDATED :
Below code works
PresentViewController(auth.GetUI(), true, false);
It seems like issue happening only with latest OAuth library. Couldn't build with previous versions of OAuth due to build errors. So created Webview based login followed by Graph API Request.

Xamarin Android: Facebook share content is empty

I have a Xamarin Forms App. Which I created a FBShareButton : Button to handle the sharing via custom renderers. This is the code in my renderer:
public class FacebookShareRenderer : ButtonRenderer
{
ShareButton sb;
protected override void OnElementChanged (ElementChangedEventArgs<Xamarin.Forms.Button> e)
{
base.OnElementChanged (e);
sb = new ShareButton(Context);
this.Control.Click += (sender, eargs) => sb.PerformClick();
sb.Click += (sender, eargs) => {
ShareLinkContent.Builder shareLinkContentBuilder = new ShareLinkContent.Builder().
SetContentDescription("Hello").
SetContentTitle("Desc");
shareLinkContentBuilder.SetImageUrl("url");
ShareLinkContent shareLinkContent = shareLinkContentBuilder.Build();
sb.ShareContent = shareLinkContent;
}
};
}
}
The share dialog opens and asks me to right something as I supposed to. However, the content does not appear and when I share they do not show. Any ideas?
I fugired this out; first the SetImageUrl should be a valid url with an Image and second I needed to SetContentUrl also, otherwise it would empty the content.