Attachment ID, Logic - google-glass

I have a Card, with this
try {
$menu_items = array();
$card = new \Google_Service_Mirror_TimelineItem();
//$card->setText("Test");
$card->setHtml('<img src="attachment:0"><img src="attachment:1">');
$menu_item = new \Google_Service_Mirror_MenuItem();
$menu_item->setAction("DELETE");
array_push($menu_items, $menu_item);
$card->setMenuItems($menu_items);
$opt_params = array();
$sr = $this->service->timeline->insert($card, $opt_params);
error_log('Send Card');
error_log(print_r($sr,true));
//return $sr;
$itemId = $sr->getId();
$params = array(
'data' => file_get_contents('https://XXXX.com/1.jpg'),
'mimeType'=>'image/jpg',
'uploadType' => 'media'
);
$sr = $this->service->timeline_attachments->insert($itemId, $params);
error_log('Send Card Attachment');
error_log(print_r($sr,true));
$params = array(
'data' => file_get_contents('https://XXXX.com/2.jpg'),
'mimeType'=>'image/jpg',
'uploadType' => 'media'
);
$sr = $this->service->timeline_attachments->insert($itemId, $params);
error_log('Send Card Attachment');
error_log(print_r($sr,true));
} catch (\Exception $e) {
error_log('Error while sending card '.$e->getMessage());
}
This works.
I get a card with two images.
Documentation states that I can use the attachments ids.. what is the logic behind that? for updates/patch only?
Aso, I am guessing if I send a card, and then I push the files, I would need to set notification.deliveryTime to the near future to avoid a weird card while the files are being uploaded?

It depends on the exact use. Some of the frameworks allow the attachments to be uploaded at the same time as the HTML for the card, so you'll be sure of the order and be sure that everything is available at once.
If you're uploading the attachments separately, it makes sense to use the attachment id that is returned when you do the upload since you have the information.
Good thought, but I wouldn't go with playing with notification.deliveryTime, since it hasn't worked very well the times I've tried using it. Instead, you might want to post the original card with some text such as "Loading..." and not send the notification at all. Then, when the attachments are uploaded, update the card to reference the attachments and set the notification so it generates the audio.
Update:
As you've noticed, you can't upload an attachment and attach it to multiple cards for the same reason you can't create a single timeline item and send it to multiple people - security. Attachments "belong" to a timeline item in the same way timeline items "belong" to a person. This is somewhat analogous to email and attachments - once you send the email out, each email has its own copy of the attachment.

Related

Google Directory API - batch add members to a group

I am using the Google Admin SDK to create, update and delete mailing lists (aka groups).
Everything works fine so far and I can create a new group and add members to it. But: Every adding of a member takes about 1s so I was thinking of a batch request to add several users to a group at once.
In the Google Admin interface it is easy to add several users at once but I didn't find any way to implement this via the API.
Is there a way to do so or do I have to loop through every user?
This works but takes a lot of time if I have to do it for every single user:
$service = new Google_Service_Directory($this->getGoogleClient());
$user = new Google_Service_Directory_Member();
$user->setEmail('test#test.com');
$user->setRole('MEMBER');
$user->setType('USER');
$service->members->insert($group_id, $user);
finally I found a solution on my own: The Admin SDK comes with a Batch class :)
To get batch requests working these steps are necessary:
When initiating the Google Client add the following line to the code
$client->setUseBatch(true);
then you can initiate the batch object
$batch = new Google_Http_Batch($client);
a little modification on the code posted above brings me to this code
foreach($arr_users as $user)
{
$userdata = new Google_Service_Directory_Member();
$userdata->setEmail($user);
$userdata->setRole('MEMBER');
$userdata->setType('USER');
$batch->add($service->members->insert($temp_list_name, $userdata));
}
finally you have to execute the request which is done by this line:
$client->execute($batch);
that's all and it works perfectly
While using the method of Christian Lange I was getting this error -
Argument 1 passed to Google\Client::execute() must implement interface Psr\Http\Message\RequestInterface, instance of Google\Http\Batch given,
So I used this instead
$client->setUseBatch(true);
$service = new Google_Service_Directory($client);
$batch = $service->createBatch();
foreach ($emails as $email)
{
$user = new Google_Service_Directory_Member(array('email' => $email,
'kind' => 'member',
'role' => 'MEMBER',
'type' => 'USER'));
$list = $service->members->insert($key, $user);
$batch->add($list);
}
$resultsBatch = $batch->execute();

How can I change my regex to get a different set of images with WWW::Mechanize?

I am making a web scraper for a website where I have to download images. I am currently using WWW::Mechanize and doing:
my #images=$mech->find_all_images(url_regex => qr/smallThumb/i);
which gives me all the images that have smallThumb in the URL.
How can I change smallThumb to zoom while retaining the previous links that have smallThumb?
You can do this:
my #smallthumbs = $mech->find_all_images(url_regex => qr/smallThumb/i);
my #zooms = $mech->find_all_images(url_regex => qr/zoom/i);
my #allimages = (#smallthumbs, #zooms);
The risk here is that you could have a URL that fits in both categories and get a dupe.
You can also go monkeying with the regex.
my #smallthumbs_or_zooms = $mech->find_all_images( url_regex => qr/smallThumb|zoom/i );

acknowledge order report amazon mws

I am using "GetReportList" api with report list type as "_GET_ORDERS_DATA" to pull order reports from amazon. But I want to pull only new orders. How can I use the "acknowledged" field to make sure that I pull only new orders(which were not previously pulled).I observed that the "acknowledged" field is true by default. Please let me know if there is a way to pull new orders only(I am trying to avoid using timestamp here)
Thanks
You need to acknowledge the order report when you picked it up, then you will only get order reports set to acknowledged false on the next call.
So you need to run this operation:
$request1 = new MarketplaceWebService_Model_UpdateReportAcknowledgementsRequest();
$request1->setMerchant(MERCHANT_ID);
$idList1 = new MarketplaceWebService_Model_IdList();
$request1->setReportIdList($idList1->withId(/* SET THE REPORT ID YOU HAVE TAKEN */));
$request1->setAcknowledged(true);
invokeUpdateReportAcknowledgements($service, $request1);
function invokeUpdateReportAcknowledgements(MarketplaceWebService_Interface $service, $request1)
{
try {
$response = $service->updateReportAcknowledgements($request1);
} catch (MarketplaceWebService_Exception $ex) {
var_dump($ex);
After you have picked up the order report, and then, you can simply request the next order report with this line:
$request->setAcknowledged(false);
Like this, only reports you haven't set to acknowledged with the first call will be shown in the list.
The first call is described in the php API, I think it's called something like SetAcknowledgmentSample, and the second call needs to be called in the getReportListSample file
I think you can set them as below which I found from sample code found in Amazon Report's API sample
$parameters = array (
'Merchant' => MERCHANT_ID,
'AvailableToDate' => new DateTime('now', new DateTimeZone('UTC')),
'AvailableFromDate' => new DateTime('-6 months', new DateTimeZone('UTC')),
'Acknowledged' => false,
);
$request = new MarketplaceWebService_Model_GetReportListRequest($parameters);
$request = new MarketplaceWebService_Model_GetReportListRequest();
$request->setMerchant(MERCHANT_ID);
$request->setAvailableToDate(new DateTime('now', new DateTimeZone('UTC')));
$request->setAvailableFromDate(new DateTime('-3 months', new DateTimeZone('UTC')));
$request->setAcknowledged(false);

open cart extension tell a friend not working

hi i have installed opencart extension tell a friend everything is good but email is not sending rest all emails when customer register and purchased are sending tell me the reason
here is the extension link also
http://www.opencart.com/index.php?route=extension/extension/info&extension_id=4348&filter_search=tell%20a%20friend
If some one has used this one please tell me
some time Opencart not work with emails on models. you need to put your logic in controller to fix this issue.
here is the solution:
get all value in your Opencart controller function and put Email logic init something like this.
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->hostname = $this->config->get('config_smtp_host');
$mail->username = $this->config->get('config_smtp_username');
$mail->password = $this->config->get('config_smtp_password');
$mail->port = $this->config->get('config_smtp_port');
$mail->timeout = $this->config->get('config_smtp_timeout');
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->request->post['email']);
$mail->setSender($this->request->post['name']);
$mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
$mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry'], ENT_QUOTES, 'UTF-8')));
$mail->send();

How to get large photo URL in one API call?

I want to display large photos in my Facebook app's feed view immediately. Is it possible to get the large photo src URL from a stream/feed using one API call? The photo id is returned in the stream/feed and one can of course then supply this photo id in an additional FQL or graph API call to retrieve all the information about that photo. However, is there a way using multi-query or batch calls to get a larger photo src url using one API roundtrip?
I haven't tried this with stream/feed photos, but the generally accepted way of doing this is:
http://graph.facebook.com/{ID of object}/picture
If you want the "large" version, you would do:
http://graph.facebook.com/{ID of object}/picture?type=large
I'm not 100% sure if this would work for an actual photo (instead of a user profile picture or page profile pic), but I have a hunch it will - the only caveat is that you obviously must have a logged in user that is authorized to view the photo (unless it's public).
If anybody is looking to this and type large is not enough, I found other solutions.
Type large is kind of small anyway (close to 200px). You can get larger image by adding i.e. ?width=1000 or ?height=1000. Facebook will return picture closest to given dimension and preserve aspect ratio. When passing both dimenstions like ?width=1000&height=1000, facebook will cut image to given dimensions (in this case square).
Use Facebook UserId (Oject ID) to get the picture.
https://graph.facebook.com/173xxxx8635/picture?type=large&redirect=false
which returns JSON data with picture URL.
{
"data": {
"is_silhouette": false,
"url": "https://fbcdn-profile-a.akamaihd.net/xxx/xyz/1cc066a2cae3f301d"
}
}
A good trick with the new api is to get the pic_cover field from the event table and to process it according to the size you want to use
I found when I was having this trouble that it turned out to be the picture I was downloading rather than the size I was setting it.
If for example I downloaded all my photos with a request of
[FBRequestConnection startWithGraphPath:#"/me/photos?fields=created_time,name,picture&type=tagged" parameters:nil HTTPMethod:#"GET" completionHandler:^(FBRequestConnection * connection, id result, NSError *error) {
NSDictionary * userData = (NSDictionary *)result;
NSMutableArray * array = [[NSMutableArray alloc] initWithArray:userData[#"data"]];
for (NSDictionary * dict in eventsToAdd) {
UIImage * image = dict[#"picture"]
}
}];
I am using the dictionary key search "picture" as I want the picture.
This though will get me a lower quality picture than if I searched for "source" in this search:
[FBRequestConnection startWithGraphPath:#"/me/photos?fields=created_time,name,source&type=tagged" parameters:nil HTTPMethod:#"GET" completionHandler:^(FBRequestConnection * connection, id result, NSError *error) {
NSDictionary * userData = (NSDictionary *)result;
NSMutableArray * array = [[NSMutableArray alloc] initWithArray:userData[#"data"]];
for (NSDictionary * dict in eventsToAdd) {
UIImage * image = dict[#"source"]
}
}];
If you go on the Facebook API explorer and search for photos and then click on the picture and source jpg links you can see the difference in size and quality.
Since changing this method I have managed to get rid of using the type parameters as it doesn't seem to make a different.
Note: I am using iPhone and not iPad or a larger screen so I don't know how this affects bigger screens.
The answer by #streetlogics works fine but only on pictures that have {object_id}.
http://graph.facebook.com/{object_id}/picture
But I also wanted large pictures for the feed's shared links, which sometimes don't have {object_id}. I finally realized that the {picture} thumbnail URL contains the encoded URL for the original site's large image:
https://external.xx.fbcdn.net/safe_image.php?d=AQBe9UvGd0vPbAHP&w=130&h=130&url=http%3A%2F%2Fskift.com%2Fwp-content%2Fuploads%2F2015%2F12%2Fpollution.jpg&cfs=1
--> contains -->
http://skift.com/wp-content/uploads/2015/12/pollution.jpg
So I made a loop that checks for {object_id} and if not present then extracts the URL from {picture}:
if(isset($post['object_id'])) {
echo "http://graph.facebook.com/".$post['object_id']."/picture";
}
elseif(isset($post['picture'])) {
echo urldecode(preg_replace('/&cfs.*/', '', preg_replace('/.*url=/', '', $post['picture'])));
}
else {
echo "no_large_image";
}