I am trying to post a Custom Open graph story in Facebook integration with SDK 4.5 , but i am not able to post it. i have created a object and action in my code
I am getting this error:
Failed to generate preview for user.com.facebook.http.
protocol.ApiException: [code] 100 [message]: (#100)
App xxxx is not allowed to create actions of type
restaurant:Wants To Visit for user xxxxx [extra]:
My code:
public void SongRequest(){
try {
// Create an object
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("og:type", "restaurant.restaurant")
.putString("og:title", "Peddlers")
.putString("og:image", "https://scontent.fdel1-1.fna.fbcdn.net/hphotos-xpt1/v/t1.0-9/11996901_943588275699701_6661729706633501716_n.jpg?oh=5ebb6e29eff2009e0f4c68f86b06923d&oe=56A8B7CE")
.putString("og:description", "Peddlers Under The Big Ben")
.putString("restaurant:contact_info:street_address", "1601 Willow Rd.")
.putString("restaurant:contact_info:locality", "Menlo Park")
.putString("restaurant:contact_info:region", "California")
.putString("restaurant:contact_info:postal_code", "160022")
.putString("restaurant:contact_info:country_name", "India")
.putString("restaurant:contact_info:email", "brian#example.com")
.putString("restaurant:contact_info:phone_number", "212-555-1234")
.putString("restaurant:contact_info:website", "https://www.facebook.com/peddlersrock")
.putString("place:location:latitude", "30.70516586")
.putString("place:location:longitude", "76.8010025")
.putString("og:url", "https://www.facebook.com/CompetentGroove")
.build();
//Then create an action and link the object to the action.
// Create an action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType("restaurant.wants_to_visit")
.putObject("restaurant", object)
.build();
//Finally, create the content model to represent the Open Graph story.
// Create the content
ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName("restaurant")
.setAction(action)
.build();
//Present the Share dialog by using the show method on ShareDialog.
ShareDialog.show(HelloFacebookSampleActivity.this, content);
} catch (Exception e) {
Log.e("Graph Stories.Exception", e.toString());
}
}
Related
I am currently working on delivering 1:1 messages to the users in Teams.
Problem Statement: I am having trouble trying to get the member details to populate the Channel Account to set the ConverstationParameters object to create conversation if the user is not part of a team. Is there a way I could get the details of the user without having the user part of a Team. I wasn't able to find any reference documentation to how to get this information for Java.
Below is my code snippet:
Setup credentials and initialize a connection using Connector Client.
Populate Channel account with recipient details for set members on Conversation Parameters Object.
Activity message = MessageFactory.text("Hello World");
MicrosoftAppCredentials credentials = new MicrosoftAppCredentials(appClientID, appClientSecret);
try (ConnectorClient client = new RestConnectorClient(serviceUrl, credentials)) {
logger.info("** Connector Client Set: {} **", client);
ConversationParameters conversationParameters = new ConversationParameters();
conversationParameters.setIsGroup(false);
CompletableFuture<ChannelAccount> user = ((Conversations) client.getConversations())
.getConversationMember(recipient, teamsInternalId); // Don't want to use this because the user has to be part of the same team which is not true in our case.
logger.info("** Aysnc get User details call **");
logger.info("** AAID: {} **", user.get().getAadObjectId());
try {
conversationParameters.setMembers(Collections.singletonList(user.get()));
} catch (ErrorResponseException e) {
logger.error("** User Error : {}**", e.getMessage());
}
conversationParameters.setTenantId(tenantId);
TenantInfo tenantInfo = new TenantInfo(tenantId);
TeamsChannelData channelData = new TeamsChannelData();
channelData.setTenant(tenantInfo);
conversationParameters.setChannelData(channelData);
CompletableFuture<ConversationResourceResponse> conversationResourceResponse = new CompletableFuture<ConversationResourceResponse>();
try {
conversationResourceResponse = client.getConversations()
.createConversation(conversationParameters);
logger.info("** Create Conversation: {} **", conversationResourceResponse.get().getId());
} catch (ErrorResponseException e) {
logger.error("** Create Conversation : {} **", e.getMessage());
}
CompletableFuture<ResourceResponse> response = client.getConversations()
.sendToConversation(conversationResourceResponse.get().getId(), message);
logger.info("** Send Conversation **", response.get().getId());
I solved the above requirement following these steps:
Check if my app is installed for the user using Graph API.
If not installed, force install the app for the user using Graph API.
Then retrieve the conversation chat id.
Use this chat id to send the message to the user.
There steps are outline here on the MSFT reference page:
https://learn.microsoft.com/en-us/microsoftteams/platform/graph-api/proactive-bots-and-messages/graph-proactive-bots-and-messages?tabs=dotnet
I hope this answer helps anyone in the same boat who would like to send messages directly 1:1 from an app to a Teams user without any mutual Team condition.
I m implementing 'net.gotev:uploadservice:4.5.1' to upload image to my server. I wrote below code but getting exception message Notification is not configured so file is not uploading. When i tried to configure notification using setNotificationConfig(new UploadNotificationConfig()), It ask for 6 Arguments to be passed in New UploadNotificationConfig().
Here is my complete code.
try {
String uploadId = UUID.randomUUID().toString();
//Creating a multi part request
new MultipartUploadRequest(this, upload_path)
.addFileToUpload(currentPhotoPath, "image") //Adding file
.addParameter("name", image_file_name) //Adding text parameter to the request
.setMaxRetries(2).setNotificationConfig(new UploadNotificationConfig())
.setUploadID(uploadId)
.startUpload(); //Starting the upload
} catch (Exception exc) {
Toast.makeText(this, exc.getMessage(), Toast.LENGTH_SHORT).show();
}
I tried but could not succeed to pass required arguments and get the method working. Can someone help to fix this.
Also attached image explaining kind of argument required. I understand first 2 but for other 4, not geting any idea how to work.
I'm not really sure how to ask the question, but I'm going to try here.
I've got a list of actions that could happen to a subject. The user of my system needs to approve these actions and does so by selecting (checkboxes) these actions and then clicking the Approve button. Some of these action might require extra data, so a new page is presented to the user. The user enters that new data. Then the backend sends the whole package off to the endpoint for modification on the database. Once completed, it will reload the page they were just on.
So this is how I have it setup:
Approve button jumps to the following method:
#PostMapping("ApproveActions")
public RedirectView approveActions(ModelandView mav, #ModelAttribute("pendingActions") PendingActionsForm pendingActions) {
boolean needsDetails = false;
ActionForm actionForm = new ActionForm();
// parse through each of the actions
pendingActions.forEach(action -> {
// verify if the action has been selected by the user.
if (action.isSelected()) {
// if needsDetails hasn't been set to true,
if (!needsDetails) {
// check to see if it is one of the special actions that needs more info
needsDetails = ActionTypes.NeedsDetails(action.typeId());
}
// build the data for the endpoint
actionForm.addActionData(action);
}
});
if (needsDetails) {
// load the new page
rv.setUrl("/extraActionDetails");
return rv; // This is not right, but it does get me to the new page.
// get data
// return to this point with that new data
actionForm.setExtraDetails(???);
}
actionService.ApproveActions(actionForm);
RedirectView rv = new RedirectView();
rv.setUrl("/subjects/" + pendingActions.getSubjectId() + "#actions-pending");
return rv;
}
The problem I'm having is I don't know how to do that part with // load the new page get data and return to this point with that new data. I've got the extra-details.jsp page built out. And it's controller can be called. Does this question make sense? Are there any tutorials out there that address this situation?
I am having some trouble while trying to share content from my app into Facebook.
I am using the following code to do it:
facebookButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if(ShareDialog.canShow(ShareLinkContent.class)){
ShareLinkContent linkContent=new ShareLinkContent.Builder()
.setContentUrl(Uri.parse(imageUrls.get(0)))
.build();
shareDialog.show(linkContent, ShareDialog.Mode.WEB);
}
}
});
My images are stored on Firebase Storage and I am able to post on Facebook as well but the title and description are both set to firebasestorage.googleapis.com like this linked image:
screenshot of share post
Note : The setContentDescription() and setContentTitle() and setImageUrl() are all deprecated.
Is there a way to set the title,and description of the shared post?
FadyDev, I don't know if you've already resolved your problem but this is what I do in place of deprecated codes:
// Builds the object
ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
.putString("fb:app_id", my_app_ID)
.putString("og:url", link_to_site)
.putString("og:type", objectType)
.putString("og:title", contentTitle)
.putString("og:description", contentDescription)
.putString("og:image", imageLink)
.build();
// Builds the action
ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
.setActionType(actionName)
.putObject(objectName, object)
.build();
// Create the openGraphContent
ShareOpenGraphContent openGraphContent = new ShareOpenGraphContent.Builder()
.setPreviewPropertyName(objectName)
.setAction(action)
.build();
return openGraphContent;
Look in the facebook doc for what action you want to use and there corresponding object type and required parameters.
https://developers.facebook.com/docs/sharing/opengraph/using-actions
https://developers.facebook.com/docs/reference/opengraph
Hope this helps!
I am using the Youtube API v3 for the first time, to receive all my videos from my youtube channel in my Java Web-application. But I like to categorize them by special categories.
What I do is, that I got my webpage and I like to display a categorized list by videos from my channel. I use a public key to identify my application.
The idea I have, is to set tags for the videos, query them and to identify the category by that special tag.
The question is, is it possible to query all the videos from my channel by a tag?
Something like I use a QueryTerm that filters by that tag and makes me receive the videos by that tag.
The code to receive the videos looks like that at the moment.
// Create the youtube object
YouTube youtube = new YouTube.Builder(HTTP_TRANSPORT, JSON_FACTORY, new HttpRequestInitializer() {
public void initialize(HttpRequest request) throws IOException{}}).setApplicationName("MyApp").build();
// Initialize the search
YouTube.Search.List search = null;
try
{
search = youtube.search().list("id,snippet");
}
catch(IOException e1)
{
throw new PipeletExecutionException("Failure during sending youtube search request");
}
// Set API-Key
search.setKey(cfg_apiKey);
search.setChannelId(cfg_channelId);
// Set Request Query
// search.setQ(queryTerm);
// search.type("playlist"); oder search.type("channel");
search.setType("playlist");
// Set Fields, filters onle the filds that are defined
search.setFields("items(id/videoId,snippet(title,description,thumbnails))");
// Call the API and consume the results
SearchListResponse searchResponse = null;
// List<SearchResult> searchResultList = searchResponse.getItems();
try
{
searchResponse = search.execute();
System.out.println(searchResponse.toPrettyString());
}
catch(IOException e)
{
throw new PipeletExecutionException("Failure during sending youtube search request");
}
dict.put(DN_YOUTUBE_LISTS, searchResponse);