How to Share media file on Twitter using gigya on Android - java

I am facing problems in sharing media file using Gigya on Twitter. Please look below at the code snippet.
It is giving a error code as 0 but on the post, only text is getting posted.
private void share(){
GSObject userAction = new GSObject();
userAction.put("title", "Text");
GSArray mediaItems = new GSArray();
try {
mediaItems.add(new GSObject("{\"src\":\"http://www.f2h.co.il/logo.jpg\", \"href\":\"http://www.f2h.co.il\",\"type\":\"image\"}"));
userAction.put("mediaItems", mediaItems);
} catch (Exception e) {
e.printStackTrace();
}
GSObject params = new GSObject();
params.put("userAction", userAction);
params.put("enabledProviders", "twitter");
GSAPI.getInstance().sendRequest("socialize.publishUserAction", params, new GSResponseListener() {
#Override
public void onGSResponse(String method, GSResponse response, Object context) {
if (response.getErrorCode() == 0) {
Log.d( "Twitter Auth Token","Session token Response Error ");
} else {
Log.d( "Twitter Auth Token","Session token Response Error "+response);
}
}
}, null);
}

Gigya does not support uploading and sharing an image within a tweet. The recommended approach would be to include a link to the image within the tweet itself.
Hope this helps

EDIT
I don't think there is a solution for this issue.
Please look in Gigya documentation and examples:
1. Share.
2. Advance share.
Answer bellow is incorrect.
End EDIT
It seems that you may be missing the 'type' in the mediaItems object.
Please look in Gigya documentation.
The output user action json should look like this:
{
'title' : 'text',
'mediaItems' : [{
'type' : 'image',
'src' : 'http://www.f2h.co.il/logo.jpg',
}
],
}

Related

WordAPI ApiException caught: Not Found

I'm following [this][1] documentation to connect to api, I want to build a JavaFX app that you can enter a word and it's retrieves it from api and I wanted to test the feature before displaying contents on GUI. Howerer I got this exception that the words is not found while I tested endpoint in their website and that word had definitions. I'm pretty new to using API perhaps I missed something that isn't shown in the documentation?
Here is my code:
public void testDetailsWords(String word,String detail) {
//String word = "lovely"; // Word
//String detail = "definitions"; // Detail
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
apiClient = Configuration.getDefaultApiClient();
apiClient.setBasePath("https://www.wordsapi.com/");
// configure authentications
Authentication auth;
auth = apiClient.getAuthentication("Default");
((ApiKeyAuth) auth).setApiKey(Apikey);
try {
WordsApi wordsApi = new WordsApi();
DetailsResponse response = wordsApi.details(word, detail);
System.out.println(response);
} catch (ApiException e) {
System.out.printf("ApiException caught: %s\n", e.getMessage());
}
}
Here is my Controller code :
#FXML
private void handleDefinitions(ActionEvent event) throws IOException {
String word =definitionsfield.getText();
String detail= "definitions";
apiCall.testDetailsWords(word,detail);
}
I would be grateful for the help.
[1]: http://restunited.com/docs/6vc24wq3ojpq
It's seems that tutorial that I tried following is very misleading which is very dissapoing, but I've learned my lesson now .
I decided to use Unirest to get request and it's worked perfectly.
If you stumble upon the link it's better not to follow that tutorial

How do I create an Alfresco site programmatically from a repository webscript?

I've implemented an Alfresco repository webscript (in Java) to programmatically create a new site.
I notice that there's a SiteService interface which I thought could be used to do this -
SiteInfo site = siteService.createSite("site-dashboard", "mySite",
"mySite", "", SiteVisibility.PUBLIC);
However, this results in the creation of a non-functional site, and although it's visible within the Alfresco Share dashboard, I'm not able to use it.
I then came across this code sample, which is doing exactly what I want. BUT the code includes a section to do authentication, involving sending the user's login and password details to a dologin web service. Don't really want to do this.
But as the user has already logged in via Alfresco Share, they should already be authenticated.
If I call the create-site webscript from my code, as shown in the example (without the initial call to dologin), I'm getting a 401 (unauthorised) return code.
So my question is, how do I tell the create-site webscript about my authentication?
I read about using an authentication ticket here. Is this ticket stored in the session, and if so, how do I access it within my Java code? If I could get the ticket, then this would be sufficient to invoke the create-site webscript.
Update: I've added the alf_ticket parameter as suggested by the comment, but I'm still getting a 401 response.
My current code is:
public NodeRef createServiceChange(String serviceChangeName) {
HttpClient client = new HttpClient();
String ticket = authService.getCurrentTicket();
PostMethod createSitePost = new PostMethod("http://localhost:8081/share/service/modules/create-site");
JSONObject siteObject = new JSONObject();
try {
siteObject.put("shortName", serviceChangeName);
siteObject.put("visiblity", "Public");
siteObject.put("sitePreset", "site-dashboard");
siteObject.put("title", serviceChangeName);
siteObject.put("description", serviceChangeName);
siteObject.put("alf_ticket", ticket);
createSitePost.setRequestHeader("Content-Type", "application/json");
createSitePost.setRequestHeader("Accept", "application/json");
createSitePost.setRequestEntity(new StringRequestEntity(siteObject.toString(), "application/json", "UTF-8"));
int status = client.executeMethod(createSitePost);
System.out.println("create a site script status :: " + status);
if (status == HttpStatus.SC_OK) {
System.out.println("Site created OK");
}
else{
System.out.println("There is error in site creation");
}
} catch (JSONException err) {
err.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
So I've managed to successfully create a site, programmatically, and here's what I did:
First, forget about writing a repository (platform) webscript. Creation of sites in Alfresco is done by invoking a Share module, so you'll need to implement either a page, or custom menu item to create a site. I was also getting a lot of problems with authentication, but if you log in to the system via Alfresco Share, and in your Javascript, use the provided Alfresco Ajax request, then authentication shouldn't be a problem.
Here are the components I used:-
Create a Share page to create your site. In the Freemarker template (.ftl) add a form to collect the site details.
Attach a button on the form to the following Javascript function. Note that I cobbled this together from various code fragments on the web, so it could use some cleaning up. But it basically works for me -
function create_site()
{
var sc_form = document.forms.namedItem('sc_form');
var name = sc_form.elements.namedItem('name').value;
var url = Alfresco.constants.URL_CONTEXT + "service/modules/create-site";
Alfresco.util.Ajax.request({
method : Alfresco.util.Ajax.POST,
url : url,
dataObj: {
sitePreset: "site-dashboard",
visibility: "PUBLIC",
title: name,
shortName: name,
description: name
},
requestContentType: Alfresco.util.Ajax.JSON,
successCallback:
{
fn: function(res){
alert("success");
alert(res.responseText);
},
scope: this
},
failureCallback:
{
fn: function(response)
{
Alfresco.util.PopupManager.displayPrompt(
{
title: Alfresco.util.message("message.failure", this.name),
text: "search failed"
});
},
scope: this
}
});
}

JSON of 10 posts from wp json rest api v1 For Android App

from a wordpress site, using json rest api, we get the json of the whole site. I want to load the json of first 10 posts from all category for android. I am using volley to load the json array and it is failing to load the whole array response as it is huge is size. I want first 10 posts and when I click load more I want the json of 11th post to 20th post. can I do so?
currently my url is like http://www.example.com/wp-json/posts
I am requesting in following code
JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET,
baseUrl,
(String) null,
new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
Log.d("json",response.toString());
listRecentPost = parseJsonResponse(response);
Log.d("LSN", listRecentPost.isEmpty() + "");
// If any data is avialable
if (!listRecentPost.isEmpty()) {
postAdapter.setRecentPost(listRecentPost);
postAdapter.notifyDataSetChanged();
/*
suppose data connection is off so error image and text will show
* but when my connection will be okk then i need to disable this image and error text
* */
errorImage.setVisibility(View.GONE);
errorMsg.setVisibility(View.GONE);
}
else {
errorMsg.setVisibility(View.VISIBLE);
errorMsg.setText("No Post Available");
}
//disable loading icon
swipeRefreshLayout.setRefreshing(false);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.d("LSN", error.toString() + "VolleyError");
// enable error iamge and text
errorImage.setVisibility(View.VISIBLE);
errorMsg.setVisibility(View.VISIBLE);
if (error instanceof TimeoutError || error instanceof NoConnectionError) {
errorMsg.setText(error.toString());
} else if (error instanceof AuthFailureError) {
errorMsg.setText(error.toString());
} else if (error instanceof ServerError) {
errorMsg.setText(error.toString());
} else if (error instanceof NetworkError) {
errorMsg.setText(error.toString());
} else if (error instanceof ParseError) {
errorMsg.setText(error.toString());
}
//again try to load data after 30 seconds
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
swapeRefresh();
}
}, 30000);
}
});
Currently I got an exception like com.android.volley.TimeoutError
And What the parameter requestBody does in JsonArrayRequest ? why we use null here?
explaining with codes will be better for me.
Thanks in advance.
Why do we use null there?
Because your request is using the HTTP-Method "Get" which passes Arguments via URL. If you use HTTP-Method "Post" you would put your request data into that JSONObject so volley can append that to HTTP-Body-Data.
you could try setting a custom RetryPolicy, since Volley timeouts after 4 seconds of waiting for repsponse - see here
Pinning down the exact problem is kinda hard with the provided information. I cant see a problem with your Request itself.
Shot in the blue:
Argument 3 (String) null, maybe pass in an empty json object.
I would definitely try to investigate deeper into volley by setting it to verbose via adb:
adb -s shell setprop log.tag.Volley VERBOSE
that way volley provides further debug information in your LogCat.
Good Luck

How to send verification code back to my application from Parse Cloud after success?

So I'm building a signup procedure that needs the user to verify their phone number by receiving a code by sms. I'm using Parse as the backend system and I'm using Twilio service which comes included in Parse to take care of the sms function. I have been successful in sending the verification code to user's number.
This is my parse cloud code:
var client = require('twilio')('ACb3....', '2b3....');
//Send an SMS text message
Parse.Cloud.define("sendVerificationCode", function(request, response) {
var verificationCode = Math.floor(Math.random()*999999);
client.sendSms({
From: "+61437877758",
To: request.params.phoneNumber,
Body: "Your verification code is " + verificationCode + "."
}, function(err, responseData) {
if (err) {
response.error(err);
} else {
response.success("Success");
}
});
});
This is the code from the app:
HashMap<String, Object> params = new HashMap<String, Object>();
params.put("phoneNumber", userNumber);
ParseCloud.callFunctionInBackground("sendVerificationCode", params, new FunctionCallback<String>() {
public void done(String result, ParseException e) {
if (e == null) {
Log.d("Parse", result);
Intent i = new Intent(SignupActivity.this, PhoneVerificationActivity.class);
startActivity(i);
} else {
Toast.makeText(SignupActivity.this, "there was a problem with connection", Toast.LENGTH_LONG).show();
}
}
});
Now I would like to know how can I send that verification code back to my android app from Parse Cloud after success, so tat I can check the verification code against the code user puts in the EditText
if (err) {
response.error(err);
} else {
*//So the code for sending the verification code back goes here:*
response.success("Success");
}
Do I need to use Json and Rest API?, how can I call and grab this verification code from the app?.
I would really appreciate your help. Thanks.
One way would be to return it in response.success...
response.success({ status: "success", verificationCode: ... });
Another way, a better way, is to not trust the client with this. Store a record of it on an object on the server... When the user enters the validation code, call back into another function to check if it is valid. An example of this type of system can be seen in this old out-dated GitHub login example: https://github.com/ParsePlatform/CloudCodeOAuthGitHubTutorial/blob/master/cloud/main.js#L116

How to pass predefined message and link parameters in facebook feed dialog using android

I want to post a predefind message with link on facebook wall without user intervention .I mean user just log into facebook and my predefind message should be post with link on user's facebook wall.
Below is my code.
public class PostOnFacebookWall {
public static void postOnWall(Facebook facebook , final Context context, final String placeName) {
Bundle params = new Bundle();
params.putString("message", placeName);
facebook.dialog(context, "feed", params ,new DialogListener() {
public void onFacebookError(FacebookError e) {
}
public void onError(DialogError e) {
}
public void onComplete(Bundle values) {
Toast.makeText(context, placeName+" for today's hangout has been posted on your facebook wall. ", Toast.LENGTH_LONG).show();
}
public void onCancel() {
}
});
}
}
I've looked so many links about my question like below
http://stackoverflow.com/questions/11316683/adding-content-to-facebook-feed-dialog-with-new-facebook-sdk-for-android
which passed all the parameter like "link","description","image" and much more.
Someone is saying that u have to pass all the parameters.I just want to predefind messages and link over that.
My message is should be "Let's hangout at " and here placeName should be a link.
And this complete msg i want to pass from my code .I don't want that my code opens dialog where user enters it's message.
If you need to post a predefined message to a User's Facebook Wall, you shouldn't be using the facebook.dialog method.
For more on why that shouldn't be used, read my answer posted here: https://stackoverflow.com/a/13507030/450534
That being said, to get the result you want, try this piece of code:
Bundle postStatusMessage = new Bundle();
// ADD THE STATUS MESSAGE TO THE BUNDLE
postStatusMessage.putString("message", "Let's hangout at " + placeName);
postStatusMessage.putString("link", "www.the_example_web_address.com");
Utility.mAsyncRunner.request("me/feed", postStatusMessage, "POST", new StatusUpdateListener(), null);
And this is where you can check the response from the Facebook API by parsing the String response:
private class StatusUpdateListener extends BaseRequestListener {
#Override
public void onComplete(String response, Object state) {
}
A point to note here is, you cannot pass a message with a link in it. To elaborate (as the earlier statement might sound confusing), You cannot pass a link in the message tag with a link that will be parsed by Facebook and show up in a post like links on FB do.
To see the difference clearly, post the status update using the code above and see how it looks on Facebook. Then, after having done that, remove this postStatusMessage.putString("link", "www.the_example_web_address.com"); from the code above and include the link in the message tag, post it and see how it looks on Facebook.

Categories