q parameter error for listUsersDrafts in Google API PHP client



Hello friends, I'm here with another blog post, third one in this week. This is probably the first time ever I'm posting three posts in one week. Great! This blog seems going well and I thought of coming back here and update this regularly to keep it stuffed with useful articles. Alright, This time I got something to tell you about the Google's php client library for PHP, and a minor problem I had while using it with Gmail API. The library is still in Beta status as they have mentioned, so of course it could have missed many things (It doesn't seem to have a proper documentation yet).

Today morning I was working on an interesting task. It was to login to one's Gmail account and get their details like Inbox, Labels, Drafts and save it in another place. That was interesting. But when I was trying to get some particular drafts by searching (using the API), I got an error in my script.

The Gmail API provides the facility to query the drafts list using a keyword and get the filtered result. This is done by passing an optional parameter "q" with the search query in the API request. This is documented in the Gmail API reference page.

So after seeing this, I tried to pass the "q" parameter in my API request using the PHP client library, but my script failed giving an error. The error was "(list): unknown parameter 'q'". I understood that the library is probably missing the support for this parameter. I dug a little bit into the client library and found my assumption was correct. Luckily this was easy to fix. All I had to do was edit one library file and add a few lines to it.

Although this fix worked and solved my problem, this is not something I would normally do. Editing core files of a library is not recommended mainly because when you update the library, your changes might disappear and the problems will arise again. But in this case, I proceeded with it because this task was not a part of a serious project and I did it for myself because I was bored ;) If you would prefer to go with this method, here is how I fixed it.

First let's see how we call the Gmail API using the client library to get the user's drafts. I hope you know how to authenticate and get the draft's list already. Here I'm focusing only on the q parameter and filtering the drafts list. So only the necessary lines of codes are shown below.

CASE 01: This is how to list all drafts.

$draftsResponse = $service->users_drafts->listUsersDrafts($userId);

This should work really fine.

CASE 02: Searching and filtering drafts using q parameter.

  $params = array(
    'q' => "search keyword"
  );

$draftsResponse = $service->users_drafts->listUsersDrafts($userId, $params);

Here we pass an optional parameter $params, which is an array having the key "q" with our query to the listUsersDrafts() method. If you use the client library downloaded as of today, it will give you an error because listUsersDrafts() method does not know any option as q. So in order to fix this, all you have to do is;

Open file google-api-php-client/src/Google/Service/Gmail.php and look for this block.

    $this->users_drafts = new Google_Service_Gmail_UsersDrafts_Resource(
        .
        .
        .
        .
            ,'list' => array(
              'path' => '{userId}/drafts',
              'httpMethod' => 'GET',
              'parameters' => array(
                'userId' => array(
                  'location' => 'path',
                  'type' => 'string',
                  'required' => true,
                ),
                'maxResults' => array(
                  'location' => 'query',
                  'type' => 'integer',
                ),
                'pageToken' => array(
                  'location' => 'query',
                  'type' => 'string',
                )
              ),
            )
        .
        .
        .

It should look like this. Locate the above code block inside. Now we need only need to add additional q parameter here. Then it will look like this one.      

        .
        .
        .
        .
            ,'list' => array(
              'path' => '{userId}/drafts',
              'httpMethod' => 'GET',
              'parameters' => array(
                'userId' => array(
                  'location' => 'path',
                  'type' => 'string',
                  'required' => true,
                ),
                'maxResults' => array(
                  'location' => 'query',
                  'type' => 'integer',
                ),
                'pageToken' => array(
                  'location' => 'query',
                  'type' => 'string',
                ),
                'q' => array(
                  'location' => 'query',
                  'type' => 'string',
                )
              ),
            )
        .
        .
        .

That's it!! now check your script again and it will work without giving you any errors and it will filter the drafts using the given keyword :) I've already created an issue in Google Client Library GitHub project and created a pull request with this fix. Hopefully they will add this in a future release. If they do not accept it, you can still use this method.

I hope this will help someone. Please do not forget to share this with your friends in Google+, Facebook and Twitter etc if you think this will be helpful to someone you know.!! Feel to leave a comment and let me know what you think about my article.

SocialEngine installation MySQL blank password error.

Today I'm going to share a useful tip with you I found recently. This is the second blog post I'm writing in this week, and it feels good to be active again with the blog after a long time. Anyway, without further ado let's get into the topic.

During last week I helped installing SocialEngine for one of my clients in his local computer (Maybe he wanted a development version of it). If you don't know what's SocialEngine, it's a social networking script written in PHP. It's not free, but it's quite cheap and it's worth the money you spend if you want to create a good feature rich social network. The installation process is really easy and even a non technical person can handle it with ease as it's straightforward. You just need to provide your database credentials and it installs it automatically. But it's not that true always! You might need to change file permissions for a few directories and files, and during the setup, it asks for your database credentials. So you might need to know a few things about "how the things work" ;)

That's why I had to be in that scenario. My client had installed MySQL in his local computer and as we all know, the default login credentials for a MySQL installation is "root" user and a blank password (unless you change it during installation.).

Now, the problem was SocialEngine did not accept blank passwords for database login details during the installation process. Please see the below image. It gives you an error as shown below. My client was frustrated and looking for a way to fix this. He didn't want to change the MySQL root password just because of this. He had a few other projects using this same login, and I guess he did not want to spend his time changing the login details everywhere. Fair enough!!


I checked the source code for the SocialEngine and found out that, by changing a small line of code you can remove this blank password validation and install it using the default mysql login details. Here's how to do it if you ever face this same problem.

Kindly note this fix is only for a specific version of Social Engine. I'm not certain if this will be the same in future releases, or it is the same in old versions of SocialEngine. I'm writing this specific to the version of SocialEngine script I received from my client. This method should definitely work if you are using the version 4.8.7. If not, please contact me or leave a comment here, I can help you with it.

This installation form validation is located in the "install/forms/DbInfo.php" file. Open that file in any code editor or a text editor you prefer, and go to the line 100 and 101. It will be something similar to this.

097.    // init password
098.    $this->addElement('Password', 'password', array(
099.      'label' => 'MySQL Password:',
100.      'required' => true,
101.      'allowEmpty' => false,
102.      'validators' => array(
103.        array('NotEmpty', true),
104.      ),
105.    ));

Now if you check the line 100, it's to validate if the password field is filled in. Since we don't have a password, we must be able to submit it with a blank value. Therefore let's change this value from "true" to "false". Then in line 101, you see it asks whether to allow empty values, yes, of course we need to allow empty values because our password is empty. So let's make it "true".

That's it, now this should look like this;

100.      'required' => false,
101.      'allowEmpty' => true,

Now if you provide your mysql login details (with your blank password), it should submit the form without giving you any errors. One thing to note is that I'm not aware of earlier or latest versions of SocialEngine as I was only working with this version of it. So please let me know if this doesn't work for your version so I can update this.

I hope this will be helpful to someone in future and save his/her time. Please let me know what you think about this in a comment below, and please do not forget to share this with your friends in Google+, Facebook and twitter if you think this will be useful to them :)

Torrent Trackers List 2016 September and October

Torrent Tracker List 2016
Torrent trackers are very popular these days with the rise of torrent usage among the Internet users. I wrote one post last year giving you a great list of working torrent trackers. I received very good responses and thanks to that article from many users and still to this date I notice many visitors come to my blog to see the old list. Although many of the torrent trackers listed on that article are still working well, I understood the list is quite old and not up to date. Many of my readers asked me to provide a new working list. So I thought I should update the blog and add a new working torrent trackers list. Here is the best trackers list you can find in the Internet up to date. These are 100% working and a fresh list I made by my own research. This is the best working torrent trackers list as at September and October 2016. (List is there at the end of this article, scroll down)

Why I made this list?

I have found many torrent trackers in Internet listed by many websites. But as you have already experienced, many of the trackers are not working most of the times or they were taken down quick making them unusable. To overcome this problem, I thought I should keep a list of working torrent trackers with me which are updated monthly so I can have the best updated trackers always with me. As I always believe, If I have spent a lot of time to find something valuable, I don't want others to waste their time too. I simply share my findings with my readers so I make a great value of the time I spent by saving other's time. That is the main reason I create posts in my blog with the trackers list I found.

What are torrent trackers?

If you do not know what is a torrent tracker, you need to understand a few basic concepts of the peer to peer file sharing method. Torrents are a basic method to share files within a group of users. Torrent trackers are keeping the necessary information of torrents and peers. In order to download a file over a torrent network, you need other users to upload the file (which is referred as "seeding"). Sometimes you may find torrents which have very less number of peers or outdated peer information. So by using a torrent tracker, you can easily get more peers to your torrent download and increase the download speed and reduce the download time.

To add trackers to a torrent which the download is in progress, you can right click on the particular file in your torrent client and go to properties, then under the peers tab you can select the option "Add Trackers" to add a new tracker. But please remember these options change according the torrent client you are using. I often use Transmission in Ubuntu. I uploaded a video in my previous blog post and I'm adding it here as well so you can see and get an idea.

I have tested these trackers and I can guarantee them to work by the time I write this article. Please see the below image to see them. I tried these trackers on a torrent file which had 0 peers and I managed to get a few peers and downloaded the file. But you should understand that these trackers can go down anytime :)

 Torrent trackers working example

In this video you can see how to add trackers to your download in the Transmission bittorrent client in Ubuntu.




Some torrent clients allow you to add multiple trackers at once. So if it permits, you can directly copy the below list and paste it into the box to add them all.

Best working torrent tracker list as at 2016 September / October:


http://tracker.flashtorrents.org:6969/announce

http://tracker.dutchtracking.nl/announce

http://tracker.yoshi210.com:6969/announce

http://tracker.tiny-vps.com:6969/announce

http://www.wareztorrent.com/announce

http://tracker.filetracker.pl:8089/announce

http://tracker.ex.ua/announce

http://tracker.grepler.com:6969/announce

http://retracker.gorcomnet.ru/announce

http://retracker.krs-ix.ru/announce

http://open.lolicon.eu:7777/announce

http://185.5.97.139:8089/announce

http://91.217.91.21:3218/announce

http://46.4.109.148:6969/announce

http://51.254.244.161:6969/announce

http://81.200.2.231/announce

http://87.248.186.252:8080/announce

http://188.165.253.109:1337/announce

http://tracker.opentrackr.org:1337/announce

http://p4p.arenabg.com:1337/announce

http://tracker.baravik.org:6970/announce

http://74.82.52.209:6969/announce

http://109.121.134.121:1337/announce

http://178.33.73.26:2710/announce

http://210.244.71.25:6969/announce

http://213.159.215.198:6970/announce

http://178.175.143.27/announce

http://atrack.pow7.com/announce

http://mgtracker.org:2710/announce

http://open.touki.ru/announce.php

http://p4p.arenabg.ch:1337/announce

http://pow7.com/announce

http://pow7.com:80/announce

http://retracker.krs-ix.ru:80/announce

http://secure.pow7.com/announce

http://t1.pow7.com/announce

http://t2.pow7.com/announce

http://torrentsmd.com:8080/announce

http://tracker.bittor.pw:1337/announce

http://tracker.dutchtracking.com/announce

http://tracker.dutchtracking.com:80/announce

http://tracker.dutchtracking.nl:80/announce

http://tracker.edoardocolombo.eu:6969/announce

http://tracker.ex.ua:80/announce

http://tracker.tfile.me/announce

http://tracker1.wasabii.com.tw:6969/announce

http://tracker2.wasabii.com.tw:6969/announce

http://www.wareztorrent.com:80/announce

http://tracker.flashtorrents.org:6969/announce

http://tracker.aletorrenty.pl:2710/announce

udp://tracker.aletorrenty.pl:2710/announce

udp://tracker.flashtorrents.org:6969/announce

udp://explodie.org:6969/announce

udp://9.rarbg.com:2730/announce

udp://tracker.opentrackr.org:1337/announce

udp://tracker.zer0day.to:1337/announce 

Please share this article with your friends in Google+, Facebook and Twitter if you think this will be useful to them! Also do not forget to leave a comment and let me know what you think about this post. It will help me to make more valuable posts similar to this in future. Mention if you know other working trackers too!!!

Solved: Ubuntu unzip with backslashes in file name.



This happened last week when I tried to extract a zip archive I received from a friend. When I extracted it in my Ubuntu Desktop, the extracted files did not have the same folder structure as the original source. I noticed the extracted files had the path as the filename. The different levels of the path were separated by backslashes. This is something I have never experienced before, and I was a bit confused at first because I wasn't aware of the original folder structure. Later only I realized the paths separated with backslashes should be in a folder hierarchy and not in the file name. So the paths shown in the file name with backslashes should be created when you extract the zip, but it didn't. So my research started to find the solution and after going through a few websites, questions and answers sites I realized that the issue was with the zip file, and not in my extracting software I used (zip).

My friend who sent me the zip archive was using Windows 8 and I was using Ubuntu 14.04. But I never had issues extracting zip archives created inside Windows, in Ubuntu before this. Then I heard from the friend that it was generated using an online tool. That could be the issue.

So the solution to this is, you have to extract the zip archive as you would do normally. Then go through each file name and see what paths and folders the file names are having and create the folders manually, then rename the file.

I know this is not the answer you expected in this blog post :) But unfortunately there was no proper easy one click solutions to this (I didn't find any). I found some Python scripts in some websites. But they all had issues. Some were not really working, and some were not giving the desired output. So I had to rely on my own skills and write a little script by myself to solve this. I'm a PHP developer, so it's the most comfortable scripting language I see around. You can write many useful automation scripts using PHP if you want :)

Here's the script I wrote. This is really easy. I'll tell you how to run this.

First, you need to have PHP installed in your Ubuntu desktop. I'm not going to teach you how to install PHP here because there are many good articles already written for that purpose. So once you have installed php, right click on your zip archive and extract it into any place you like.

Once you extracted it, go inside the folder. Now you should see all the extracted files in the same folder, with long file names having backslashes in their names. Don't worry.

Now right click inside that folder and create a new file. Name it as anything you like, but make sure it's a php file. That means it should end with a ".php" extension. I would name it as "create_folders.php".

Open the file you created with a text editor, or any code editor, IDE if you have. Then paste the below php script in the file and save it.

<?php

$files = glob('*');

foreach ($files as $file) {
    $new_file = str_replace("\\", "/", $file);

    if (!is_dir(dirname($new_file))) {
        mkdir(dirname($new_file), 0777, true);
    }

    rename($file, $new_file);
}

?>

Then open your terminal by pressing "CTRL + ALT + T", and CD into the folder where you extracted the zip archive, and run the php script by issuing the command;

php create_folder.php

Here's an example if you find it difficult to understand.

Let's assume I extracted the zip archive into "myfolder", and created the new file with php script as I explained above. Now if you list the "myfolder", it should be something similar to below list.

css\styles.css
css\common.css
images\home\bg.png
images\logo.png
index.html
create_folder.php <---- This is the new file we created.

Now open your terminal. CD into this folder..

nimeshka@PC:~$CD myfolder
nimeshka@PC:~/myfolder$ php create_folder.php

It will take a few seconds if your folder is large. Then once it's finished, go back to your folder and see the files are nicely arranged and new folders are created :)

So that's it guys. Hope this is helpful. Please let me know what you think about this by leaving a comment. Don't forget to share this article in Facebook, Twitter, G+ if you think it will help someone else :)