Attach photo to Activity through Google + Domains API - google-plus

Im trying to post an activity with an image to a google+ domain with the new google + domains API
Posting an activity is working fine but when i try to attach a photo to it, i receive a 500 error with null description.
This is the code:
String msg = "Activity with photo";
// Create a list of ACL entries
PlusAclentryResource resource = new PlusAclentryResource();
resource.setType("domain"); // Share to domain
List<PlusAclentryResource> aclEntries = new ArrayList<PlusAclentryResource>();
aclEntries.add(resource);
Acl acl = new Acl();
acl.setItems(aclEntries);
acl.setDomainRestricted(true); // Required, this does the domain restriction
// Create a new activity object
Activity activity = new Activity()
.setObject(new Activity.PlusObject().setOriginalContent(msg))
.setAccess(acl);
// Attach the link
Activity.PlusObject.Attachments attachment = new Activity.PlusObject.Attachments();
attachment.setObjectType("photo");
attachment.setUrl( "http://c299813.r13.cf1.rackcdn.com/MuseeduLouvre_1335428699_org.jpg" );
attachment.setId( randomId ); //if not specified, google returns an error with "you must specify the photo id"
List<Activity.PlusObject.Attachments> attachments = new ArrayList();
attachments.add(attachment); // You can also add multiple attachments to the post
activity.getObject().setAttachments(attachments);
activity = plus.activities().insert("me", activity).execute();
When the code calls the execute, i receive this error:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 500
{
"code": 500,
"message": null
}
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
The same code but with the attachemnt lines commented works fine. Has someone managed to create an activity with an image? any clue?
Thanks in advance.

Directly attaching a photo via URL isn't possible. The process works slightly differently, as described here: https://developers.google.com/+/domains/posts/attaching-media
If you don't have the actual binary data of the photo you will first have to "download" the photo. Then you can upload the actual photo data via the media().insert method, which will give you the Photo Id which you can then use in attachment.setId().
setUrl isn't necessary in this case.
If you want to attach a photo as URL, this could also be handled like an article attachment (same as if you would just copy/paste the URL into a Google+ post). In that case you would use attachment.setObjectType("article") and only set the Url. The id isn't necessary in this case.

Related

Brach URL is giving "Trouble creating a URL" when tracking is disabled and trying to create a short url

For GDPR compliance reasons, we have disabled link tracking in our Android and iOS applications and using generate Short URL method for getting the short link of the item, we want to share. But when we are calling generateShortUrl() method, it gives "Trouble creating a URL. Tracking is disabled. Requested operation cannot be completed when tracking is disabled" error and the URL that is returned does not work when shared on Facebook or an email when the user clicks on it.
Our concern is though tracking is disabled and Branch is unable to create a short URL, it shall return the working long URL at least. Please let us know if we have to do something here to make it work on our apps.
Can you please check if you set generateShortUrl like the following example codes for Android? You can also find detailed information about creating deep link
Android : https://docs.branch.io/apps/android/#create-deep-link
iOS : https://docs.branch.io/apps/ios/#create-deep-link
.
import io.branch.indexing.BranchUniversalObject;
import io.branch.referral.Branch;
import io.branch.referral.BranchError;
import io.branch.referral.util.LinkProperties;
BranchUniversalObject buo = new BranchUniversalObject();
LinkProperties lp = new LinkProperties();
buo.generateShortUrl(this, lp, new Branch.BranchLinkCreateListener() {
#Override
public void onLinkCreate(String url, BranchError error) {
if (error == null) {
Log.i("BRANCH SDK", "got my Branch link to share: " + url);
}
}
});
Also, if you have any further questions, please contact support#branch.io to give better assistance.

Iron Web Scraper - Login

I've read the tutorials to log into a website prior to scraping it, but it just ain't workin'. I constructed a HttpIdentity object, added it to the Identities collection, and processed the request, but the page returned to scrape was still the login page. There isn't a lot about this on their website and documentation. Here's my code for that:
var identity = new HttpIdentity
{
UseCookies = true,
NetworkUsername = _username,
NetworkPassword = _password
};
Identities.Add(identity);
Request(_uri, Parse, identity);
In the Parse method I get a Response object returned with a Status Code of 200, and the "WasSuccessful" property of Response is "true". It seems that I should be redirected to the page I was trying to access, but I'm just getting the login html.
Is there something I'm missing?
I wasn't able to find a solution using the Iron Web Scraper, but I was able to do it with ScrapySharp, which is a free utility, so it worked out. ScrapySharp is able to mimic a browser to a degree, so navigation and submitting forms is pretty easy.
var browser = new ScrapingBrowser();
var homepage = browser.NavigateToPage(_Uri); // login Uri
var form = homepage.FindForm("login"); // get form by name
form.Method = HttpVerb.Post;
form["username"] = "my_username"; // get form fields by id
form["password"] = "my_password";
var resultPage = form.Submit(); // login
var loggedInPage = browser.NavigateToPage(new Uri("https://path.to.target.page"));
And that's it. I'm not sure what the problem was with Iron Web Scraper. Maybe some ajax on the login page. In any case, this code is working for me now.

Make hyperlink in webmail back to mvc4 project

I have a webmail and i want the user to press on a picture in the webmail and then be linked back to my mvc project view. I don't have a real domain yet so i can't type www.mysite.com. I want to be able to link to the view without depending on which domain the site is currently running on.
in my webmail i have the body that looks like this:
string Body = "<b>Välj ett alternativ!</b><br><br><a href='cid:path4'/><img src='cid:Happy'/ alt='HTML tutorial' width='120' height='120'></a><input type='image' src='cid:Orange'/ name='image' width='120' height='120'><input type='image' src='cid:Mad'/ name='image' width='120' height='120'>";
where the cid:path4 is i want the url och what ever so that i linkes me back to my project.
You'll have to format the absolute path into the body text from your controller action (or pass it through to whatever method generates the body):
var path = Request.Uri.AbsoluteUri;
var emailBody = String.Format("Your email body. Link", path);
Or, you could link to another controller action with Url.Action:
var path = Url.Action("MyAction", "MyController", null, "http");
var emailBody = String.Format("Your email body. Link", path);
Of course, this all assumes that this email is sent by a controller action - if it's not, it may not be possible to determine the absolute URI of the website.

Posting canvas image to user's wall via facebook javascript sdk

I have dynamically created a html canvas image. I want to post it to facebook user's wall via javascript sdk. What I am doing is
I tried to convert canvas into a javascript image object & provide finalimage in fb.ui method
var temp = canvas.toDataURL("image/png");
var finalimage=temp.replace(/^data:image\/(png|jpg);base64,/, "");
FB.ui(
{
method: 'feed',
name: 'The Facebook SDK for Javascript',
caption: 'Bringing Facebook to the desktop and mobile web',
description: (
'A small JavaScript library that allows you to harness ' +
'the power of Facebook, bringing the user\'s identity, ' +
'social graph and distribution power to your site.'
),
link: 'https://developers.facebook.com/docs/reference/javascript/',
picture: finalimage
},
function(response) {
if (response && response.post_id) {
alert('Post was published.');
} else {
alert('Post was not published.');
}
}
);
But I am getting an error
Error Message: picture URL is not properly formatted
Can anyone please help how do I do that??
You need to save the image at your server for doing that, your image must be outside Facebook, because FB.ui "FEED" does not accept base64 encoded data as picture, its impossible .
Its very large data, and if you try to short the base64 code into a url shorteer, you will find difficulties too .
What you can do, and what i am doing, is use an PHP server to get the Base64 data, and convert it into image, like a dynamic image, ok? But a memory problem will be created .
Another option is (really) posting the canvas as an image on user profile, so you will need use FB.api for that, instead of FB.ui, feed dialog is used for sharing links, and, canvas doesnt have Title, Description, proprieties .
After posting the image, you will get an response, with ID, that is post ID, and this cannot be used on Feed as Link or Image proprietity, but you can use Share Dialog, if you want to share the post .
That is piece of cake, i done that, and recommend you do the same .
Posting Canvas as images usin API on Facebook Platform is great, you can do that using JavaScript SDK .

How to upload photo with Rubymotion?

I am building an iOS app using Rubymotion.
I need to let the user snap a photo with the camera and then upload it to a Rails 3 backend (with Paperclip) using the BubbleWrap Http module (or any better?).
How can I do this?
This is my code:
controller = UIImagePickerController.alloc.init
controller.sourceType = UIImagePickerControllerSourceTypeCamera
controller.mediaTypes = [KUTTypeImage]
controller.allowsEditing = true
controller.delegate = self
self.navigationController.presentModalViewController(controller, animated:true)
This I use after taking the shot:
metadata = info.objectForKey(UIImagePickerControllerMediaMetadata)
the_image = info.objectForKey(UIImagePickerControllerOriginalImage)
image = view.viewWithTag 3
image.image = the_image
picker.dismissModalViewControllerAnimated(true)
This is my upload code:
data = {access_token: TOKEN, id: task, image: image}
BubbleWrap::HTTP.get("#{URL}#{project}/message", {payload: data}) do |response|
if response.ok?
json = BubbleWrap::JSON.parse(response.body)
if json['total'] > 0
infos = json['taskinfos'].map {|ej| self.from_json(ej["taskinfo"])}
block.call(true, infos)
else
block.call(false, nil)
end
else
block.call(false, nil)
end
end
Uploading images should be done via a POST request and not a GET request like you have done. Most web servers have a limit to how big a GET request can be, and it is usually 8k, read here for more info maximum length of HTTP GET request? , so it's not suitable for images.
Play around with bubble motion and look at the requests in the log files on the server to see what comes out. Try to make the request look like a request made from within rails itself, ie from a web page where you upload to the the controller.
So you could change the request to POST and let people know what error messages you get.