Sunday, August 19, 2018

How to get YouTube video thumbnail from the YouTube video ID?



How to get YouTube video thumbnail from the YouTube video ID | get a YouTube video thumbnail from the YouTube API | How we can use the YouTube Video ID to Retrieve the Video Thumbnails

As we know each YouTube video has thumbnail images. So here is a quick and very simple tip to get thumbnail images with the help of youtube video id.   


http://img.youtube.com/vi/[your-youtube-video-id]/0.jpg
http://img.youtube.com/vi/[your-youtube-video-id]/1.jpg
http://img.youtube.com/vi/[your-youtube-video-id]/2.jpg
http://img.youtube.com/vi/[your-youtube-video-id]/3.jpg


We have some other options, Please check below examples -


The default thumbnail image is:
http://img.youtube.com/vi/[your-youtube-video-id]/default.jpg

For the high-quality thumbnail:
http://img.youtube.com/vi/[your-youtube-video-id]/hqdefault.jpg

For medium quality thumbnail:
http://img.youtube.com/vi/[your-youtube-video-id]/mqdefault.jpg

For standard definition thumbnail:
http://img.youtube.com/vi/[your-youtube-video-id]/sddefault.jpg

For maximum resolution thumbnail:
http://img.youtube.com/vi/[your-youtube-video-id]/maxresdefault.jpg


What is my Video ID: This is very simple to find YouTube video ID. First, open youtube and go to the YouTube video. Now, Look at the URL of that video, at the end of URL, you can see a combination of numbers and letters after an equal sign (=). This is the video id for that video. Please check id in below image :




Thursday, August 16, 2018

Get user current location in ionic 2 | ionic 3

Get Geolocation (Latitude and Longitude) in Ionic 2 -






In this post, We will learn, how to get the user current latitude and longitude using the Geolocation native plugin (Ionic Plugin).

Geolocation : Geolocation is the identification of the real world geographic location of an object. Geolocation works through a pre-built GPS in a device. This provide location in the form of latitude and longitude of device.


Now, We are going to create a code flow for this. This is very simple to use.

Step 1: Install Geolocation plugin in your project by using below command -

ionic cordova plugin add cordova-plugin-geolocation
npm install --save @ionic-native/geolocation

For iOS platform you have to add below lines in project configuration.xml file -

<edit-config file="*-Info.plist" mode="merge" 
target="NSLocationWhenInUseUsageDescription"> <string>This app required to access your device location.</string> </edit-config>


Step 2 : Now add this plugin to your app's module (app.module.ts) -

import { Geolocation } from '@ionic-native/geolocation';

Add "Geolocation" in providers -

 providers: [
    Geolocation,
    {provide: ErrorHandler, useClass: IonicErrorHandler}
  ]


Step 3 : Now use below code in your TS file where you want to use this plugin -

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Geolocation } from '@ionic-native/geolocation';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  public latitude:any;
  public longitude:any;

  constructor(public navCtrl: NavController, private geolocation: Geolocation) {

  }

  getLocation()
  {
    this.geolocation.getCurrentPosition().then((resp) => {
       this.latitude=resp.coords.latitude;
       this.longitude=resp.coords.longitude;
    }).catch((error) => {
      console.log('Error getting location'+JSON.stringify(error));
    });
  }


}

Step 4 : Use below code in your HTML file -
<ion-header>
  <ion-navbar>
    <button ion-button menuToggle>
      <ion-icon name="menu"></ion-icon>
    </button>
    <ion-title>Geolocation Example</ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding class="login">

  <h3>Current Latitude: {{latitude}}</h3>
  <h3>Current Longitude: {{longitude}}</h3>
  <button ion-button full primary (click)="getLocation()">Get Location</button>

</ion-content>



This is done from code side. All the best 👍

Wednesday, August 1, 2018

Contact us form in php

Contact us form in php

In this post we will learn below functionality :

1. HTML UI of contact us page.
2. HTML validations.
3. Manage CSS.
4. Email all details on our email id.

1. HTML UI of contact us page: Here is the example of basic HTML form for contact us page.


   
      <h2>Contact Form</h2>
<form id="form" method="post" action="contact_us.php">
    <fieldset>
      <label><input name="name" id="name" placeholder="Name*" required type="text"></label>
      <label><input name="email" id="email" required type="email" placeholder="Email*"></label>
      <label><input name="phone_no" required type="text" placeholder="Phone*"></label>
      <label><textarea name="query" required placeholder="Message*"></textarea></label>
      <div class="btns">
        <input class="send-btn" type="submit" value="Send" name="">
      </div>
    </fieldset>  
</form>
   
 

Here,
method="post" (To post data on the server by POST method)
action="contact_us.php" (Form data will post on contact_us.php page)




2. HTML validations : Below are the HTML 5 validations which we used in HTML form  
required (This is the required validation of HTML 5)
required type="email" (This is for required with valid email address)


3. Manage CSS: Use below CSS to style your submit button 

.send-btn{
width:100%;
height:30px;
margin-bottom:10px;
background-color: #ff9000;
color: #fff;
border-radius: 10px;
}

4. Email all details on our email id: Create a contact_us.php file and add below code in this file 


$tryAgainUrl="<a href='contacts.html'>Try Again</a>";
if(!empty($_POST))
{
if( $_POST['name'] && $_POST['query'] && $_POST['phone_no'] && $_POST['email'])
{
$name=$_POST['name'];
$query=$_POST['query'];
$phone_no=$_POST['phone_no'];

/* email send code start */
$from="info@yourdomain.com";
$to="support@yourdomain.com";
$email=$_POST['email'];
$subject = 'Contact us query';
$message ="Name : ".$name."\r\n\r\n";
$message.="Email : ".$email."\r\n\r\n";
$message.="Phone No :- ".$phone_no."\r\n\r\n";
$message.="Message :- ".$query."\r\n\r\n";

$headers = "From: $from\r\nReply-to: $email";
$sent = mail($to, $subject, $message, $headers);
/* email send code end */

header("Location: contacts.html"); /* Redirect browser */
exit();
}else{
echo "Invalid Details. ".$tryAgainUrl;
}
}else{
echo "Invalid Details. ".$tryAgainUrl;
}
?>


Here :
mail(to,subject,message,headers);

$to = This is required. (Receiver email address)
$subject = This is required. (Subject of the email)
$message = This is required. (Defines the message to be sent) 
$headers = This is Optional. (Specifies additional headers, like From, Cc, and Bcc)








Friday, July 27, 2018

How to reprogram your mind for SUCCESS!

How to reprogram your mind for SUCCESS!



We all know what is brain? An organ which is responsible for controlling and coordinating our mental and physical actions. But if I ask you what is mind? Then some will say it' some where in  brain , some heart and some will any other part of body but this all is wrong. Because our mind is not a physical object to which you can point and say this is mind. Our mind is formless which makes us aware and let's us understand objects in world. 

In psychological level mind is divided into 3 parts: 
1. Conscious mind
2. Subconscious Mind
3. Unconscious mind 

For now I am going to explain  Conscious mind and Subconscious Mind.

Conscious mind is our active mind which makes decisions by analysing logically, planning ,with focus. But some decisions we don't take by conscious mind because this decisions are taken by our Subconscious Mind.

Subconscious Mind makes decisions from our emotions, habits,& past experiences.
Let's take an example to understand the difference between both.
when we are learning how to drive a car, we are driving "consciously" - every action is a "conscious" action - like changing gears, applying brakes, turning and so on.  After a few years of driving experience, we drive the car subconsciously.  The feet are doing their job, the hands theirs, and we are usually relaxed.
Our conscious mind is only 10% of our mind and subconscious mind uses 90% of our mind.
Just like an iceberg which seems small at the top but inside water it's big enough. Top can be compared as conscious mind and the part in the water with subconscious mind.
Subconscious Mind has  huge power which can change your life if you REPROGRAM it. With this  video you can learn to reprogram you subconscious mind for SUCCESS. Thank you!


Youtube channel video url : https://youtu.be/SdSKDd5RyBA


Tuesday, July 24, 2018

CocoaPods was not found "When add remove plugin in ionic"

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): CocoaPods was not found. Please install version1.0.1 or greater from https://cocoapods.org/

Issue : Some ionic plugins needs CocoaPods for the iOS platform



To resolve this issue you need to run below command in your project :

sh-3.2# pod setup

If you get "pod: command not found" error, You need to install pod in your project. To install pod use this command in your project :  

sudo gem install cocoapods

If you get an error like this "You cannot run CocoaPods as root", Please run above without root (without doing login in your terminal)

Note: This command will take time to install cocoapods.

Now, after completion of "cocoapods" installation, Run below command in your project to setup pod :

pod setup

If you get an error like this "You cannot run CocoaPods as root", Please run above without root.


Wednesday, July 18, 2018

How to start a startup

How to start a startup in hindi


Zero to One : Notes on Startups or How to Build the Future by Peter Thiel ➤ Summary 




Youtube channel video url : https://youtu.be/lsyjiOq7keU  



Have you ever wondered how Google,Apple,Amazon etc became so successful and what diffrentiate these successful companies  from other companies. Author Peter Theil the cofounder of PayPal teaches in zero to one how we can create a successful business or startup and can change the world. Here is the summary of the book.

1) Progress from Zero to One :

Every movement in business happens once. The next Bill gates will not build an operating system. The next Mark Zuckerberg won't create a social networking site. Similarly the next Larry page won't create a search engine.
So, if you are coping them, then you are not learning from them. 
When you copy something that already exists you go from 1 to n. But when you create something new and unique that no one ever created you go from 0 to 1.
Ex: if at the time of typewriters you thought of creating a better and more iterations typewriter then you have gone from 1 to n , also called horizontal progress.
But if you thought of creating a computer word processor then you had gone from 0 to 1, also called vertical progress.
In vertical progress nothing is copied.
Like the successful companies Google, PayPal etc they got success because of their unique ideas and work.

2) Competition or Monopoly :

In 2013 Apple's market capatilization was $500 billion and Google , Microsoft combined was 467$ billion. Three years ago both  google and Microsoft was way ahead from Apple but because of competition they compited, and Apple won. Competition doesn't  encourages us for betterment but it reduces our power and gives loss. So avoid compotition for success. For getting success find a market where competition is less.
Opposite of competition is Monopoly. Monopoly means being the best in your work so that everyone comes to you only. The company do so much better that no one else can survive.
Google is a great example of monopoly.
If I tell you to search something then you will definitely Google it. 

So for a Successful Startup remember to create something new and become best in your field.

Monday, July 16, 2018

Vimeo video upload in ionic 2 | ionic 3 | ionic 4

How to upload video on vimeo from ionic :

In this artical i will explain how to upload video on vimeo from ionic 2 | ionic 3 | ionic 4 app. This is very simple process, Just make sure you should have knowledge about Camera, File, FileTransfer plugins. With this plugins we will upload videos on vimeo.


First you need to create app on vimeo.com. After creation of app you’ll get a Client ID and Client Secret for your application you create.
Register a new application : https://vimeo.com/log_in

Please follow below steps to generate authorization :

1. Get your API key : You’ll need a Client ID and Client Secret for each application you create. To create a key, you’ll need to supply vimeo with some basic information about your application. Don’t worry if you’re not sure about all of the information, you can always edit it later.

2. Get an access token : To make API requests you will need an Access token. If you want to make requests on behalf of a user, that token must be authenticated. You can generate access token from vimeo for selected app.



Now we will start to integrate vimeo video upload in our ionic app :

Step 1: Install camera, file and file transfer plugins by using below ccommand 

 $ ionic cordova plugin add cordova-plugin-camera
 $ npm install --save @ionic-native/camera

 $ ionic cordova plugin add cordova-plugin-file
 $ npm install --save @ionic-native/file

 $ ionic cordova plugin add cordova-plugin-file-transfer
 $ npm install --save @ionic-native/file-transfer


Step 2: Import plugins in page 

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Camera, CameraOptions } from '@ionic-native/camera';
import { Http, Headers, RequestOptions } from '@angular/http';
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer';
import { File } from '@ionic-native/file';


Now add plugins in provider list :

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
  providers: [Camera,File, FileTransfer]
})

Add plugins in constructor :

constructor(public navCtrl: NavController,private camera: Camera, public http:Http, private transfer: FileTransfer, private file: File) {

  }


Step 3: Add code to select video from mobile by using camera plugin 

selectVideo(){
    
const options: CameraOptions = {
 quality: 100,
 allowEdit:true,
 destinationType: this.camera.DestinationType.FILE_URI,
 sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
 mediaType: this.camera.MediaType.VIDEO,
 saveToPhotoAlbum: true
}

this.camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64:
let base64Image = 'data:image/jpeg;base64,' + imageData;
this.currentVideo = imageData;
this.generateVideoUploadUrl();
}, (err) => {
// Handle error
});

}

Note : On vimeo we need to follow 2 steps for video upload. First we need to generate video upload url then we need to upload video on that url.

Step 4: Now generate upload video url from vimeo

generateVideoUploadUrl(){

let url='https://api.vimeo.com/me/videos';
 let params ={
   "upload" : {
     "approach" : "post",
     "redirect_url" : ""
 },
 "name" : "My Video",   // video name
 "privacy" : {
     "embed" : "private"       // public for public video
 }
};
 
 let headers = new Headers({ 'Authorization':'Bearer XXXXXXXXXXXXXXXXXXXXXXX(Access Token)','Content-Type': 'application/json','Accept':'application/vnd.vimeo.*+json;version=3.4' });
 let options = new RequestOptions({
   headers: headers
});

let repos = this.http.post(url, params, options).subscribe(
 data => {
   let res = data.json();
   console.log(JSON.stringify(res));

   let url = res.upload.upload_link;
   this.uploadVideo(url);
 },
 err => {
   console.error("Error : " + err);
 },
 () => {
   //this.commonMethod.hideLoader();
   console.log('getData completed');
 }
);
}


Step 5: Upload video on vimeo 

uploadVideo(url){

const fileTransfer: FileTransferObject = this.transfer.create();
let fileName=this.currentVideo.substr(this.currentVideo.lastIndexOf('/')+1);

let options: FileUploadOptions = {
 fileKey: 'file',
 fileName: fileName, 
 httpMethod: 'PUT',
 headers: {'Authorization':'Bearer XXXXXXXXXXXXXXXXXXXXXXX(Access Token)','Tus-Resumable':'1.0.0','Upload-Offset':'0', 'Content-Type': 'application/offset+octet-stream' }
};

fileTransfer.upload(this.currentVideo, url, options)
.then((data) => {
 // success
 console.log('s='+JSON.stringify(data));
}, (err) => {
 // error
 console.log('f='+JSON.stringify(err));
});




It's done. Please check video on vimeo. 


This is the full code for your TS file :

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Camera, CameraOptions } from '@ionic-native/camera';
import { Http, Headers, RequestOptions } from '@angular/http';
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer';
import { File } from '@ionic-native/file';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
  providers: [Camera,File, FileTransfer]
})

export class HomePage {
  public currentVideo:any;
  constructor(public navCtrl: NavController,private camera: Camera, public http:Http, private transfer: FileTransfer, private file: File) {

  }

  selectVideo(){
    
const options: CameraOptions = {
 quality: 100,
 allowEdit:true,
 destinationType: this.camera.DestinationType.FILE_URI,
 sourceType: this.camera.PictureSourceType.PHOTOLIBRARY,
 mediaType: this.camera.MediaType.VIDEO,
 saveToPhotoAlbum: true
}

this.camera.getPicture(options).then((imageData) => {
// imageData is either a base64 encoded string or a file URI
// If it's base64:
let base64Image = 'data:image/jpeg;base64,' + imageData;
this.currentVideo = imageData;
this.generateVideoUploadUrl();
}, (err) => {
// Handle error
});

}
    
generateVideoUploadUrl(){

let url='https://api.vimeo.com/me/videos';
 let params ={
   "upload" : {
     "approach" : "post",
     "redirect_url" : ""
 },
 "name" : "My Video",   // video name
 "privacy" : {
     "embed" : "private"       // public for public video
 }
};
 
 let headers = new Headers({ 'Authorization':'Bearer XXXXXXXXXXXXXXXXXXXXXXX(Access Token)','Content-Type': 'application/json','Accept':'application/vnd.vimeo.*+json;version=3.4' });
 let options = new RequestOptions({
   headers: headers
});

let repos = this.http.post(url, params, options).subscribe(
 data => {
   let res = data.json();
   console.log(JSON.stringify(res));

   let url = res.upload.upload_link;
   this.uploadVideo(url);
 },
 err => {
   console.error("Error : " + err);
 },
 () => {
   //this.commonMethod.hideLoader();
   console.log('getData completed');
 }
);
}
    
uploadVideo(url){

const fileTransfer: FileTransferObject = this.transfer.create();
let fileName=this.currentVideo.substr(this.currentVideo.lastIndexOf('/')+1);

let options: FileUploadOptions = {
 fileKey: 'file',
 fileName: fileName, 
 httpMethod: 'PUT',
 headers: {'Authorization':'Bearer XXXXXXXXXXXXXXXXXXXXXXX(Access Token)','Tus-Resumable':'1.0.0','Upload-Offset':'0', 'Content-Type': 'application/offset+octet-stream' }
};

fileTransfer.upload(this.currentVideo, url, options)
.then((data) => {
 // success
 console.log('s='+JSON.stringify(data));
}, (err) => {
 // error
 console.log('f='+JSON.stringify(err));
});

}

}