Posts tagged with java

This is my first time trying to do react-native bridge. Problem is it always says it couldnt find the dependency, irrespective of my integration, I should be able to download the dependency right? I am trying to bridge: https://developer.imepay.com.np/#/andriod-sdk

I am not being able to implement the dependecy:

implementation 'com.swifttechnology.imepaysdk:payment-service:4.0.1

In my main/java/imepayintegration: ImepayModule.java:

package com.reactnativeimepay; import androidx.annotation.NonNull; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; import com.facebook.react.bridge.Promise; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; import java.util.Map; import java.util.HashMap; import com.swifttechnology.imepaysdk.IMEPayment; import com.swifttechnology.imepaysdk.IMEPaymentCallback; import com.swifttechnology.imepaysdk.ENVIRONMENT; public class ImepayModule extends ReactContextBaseJavaModule {     private final ReactApplicationContext reactContext;     public ImepayModule(ReactApplicationContext reactContext) {         super(reactContext);         this.reactContext = reactContext;     }     @Override     public String getName() {         return "ImepayModule";     }     @ReactMethod     public void performPayment(String merchantCode, String merchantName, String module,                                String username, String password, String referenceValue,                                String amount, String merchantTransactionRecordingUrl,                                Promise promise) {         IMEPayment imePayment = new IMEPayment(reactContext, ENVIRONMENT.TEST);         imePayment.performPayment(merchantCode,                 merchantName,                 merchantTransactionRecordingUrl,                 amount,                 referenceValue,                 module,                 username,                 password,                 new IMEPaymentCallback() {                     @Override                     public void onSuccess(int responseCode, String responseDescription,                                           String transactionId, String msisdn,                                           String amount, String refId) {                         promise.resolve("Payment successful");                     }                     @Override                     public void onError(int responseCode, String responseDescription) {                         promise.reject("ERROR", responseDescription);                     }                 });     } } 

ImepayPackage.java:

package com.reactnativeimepay; import java.util.Arrays; import java.util.Collections; import java.util.List; import com.facebook.react.ReactPackage; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.uimanager.ViewManager; public class ImepayPackage implements ReactPackage {     @Override     public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {         return Arrays.<NativeModule>asList(new ImepayModule(reactContext));     }     @Override     public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {         return Collections.emptyList();     } } 

I am working on automating the upload of video assets to the Google Ads asset library. The process involves first uploading the video to YouTube via the YouTube Data API and then attaching the uploaded video's ID to Google Ads using the Google Ads API.

Here’s a snippet of the code I'm using to upload a video to YouTube:

public void upload(Credential credential) throws Exception {     YouTube youtubeService = new YouTube.Builder(         new NetHttpTransport(), JacksonFactory.getDefaultInstance(), credential)         .setApplicationName("youtube-upload")         .build();     File initialFile = new File("src/main/resources/test.mp4");     InputStream targetStream = new FileInputStream(initialFile);     InputStreamContent mediaContent = new InputStreamContent("video/*", targetStream);     Video videoObjectDefiningMetadata = new Video();     VideoSnippet snippet = new VideoSnippet();     snippet.setTitle("Test Video " + System.currentTimeMillis());     snippet.setDescription("A video uploaded via YouTube API");     snippet.setTags(Arrays.asList("test", "video", "upload"));     VideoStatus status = new VideoStatus();     status.setPrivacyStatus("private");     videoObjectDefiningMetadata.setSnippet(snippet);     videoObjectDefiningMetadata.setStatus(status);     YouTube.Videos.Insert videoInsert = youtubeService.videos()         .insert(List.of("snippet", "statistics", "status"), videoObjectDefiningMetadata, mediaContent);     Video returnedVideo = videoInsert.execute();     System.out.println("Uploaded video ID: " + returnedVideo.getId());     adsService.uploadVideo(returnedVideo); } 

The code works as expected and uploads the video to YouTube, retrieves the video ID, and uses it for Google Ads. However, I am hitting YouTube API upload quotas pretty quickly, and this is causing problems for scaling this process.

My Question:

How can I handle or mitigate YouTube API quota limits when uploading videos in bulk? Is there a way to optimize or reduce the number of quota points consumed when uploading videos via the API? Are there any alternative approaches or best practices to avoid hitting the quota limit?

Notes:

I am already following YouTube’s best practices for uploads (setting the video privacy to “private,” limiting tags, etc.), but the quota usage is still significant. The YouTube API quota system allocates 1600 units per day for each project by default. Each video upload request consumes around 1600 units (as per the documentation).

Relevant API Documentation:

  1. YouTube Data API
  2. Google Ads API
  3. Youtube Support Post

We are currently in the process of implementing the Whatsapp Embedded Signup fucntionality that will be required by Twilio later in the year.

We've followed the documentation and we think we haven't made any mistakes.

In our front-end, everything works fine. The correct Whatsapp Business Account ID and Phone Number ID are retrieved from the Meta window.

After this we attempt to register these credentials to a new subaccount in Twilio using Twilio's Java library. We retrieve the phone number to use as the sender using Meta's API.

The step that fails is registering a Whatsapp Sender on the Twilio subaccount. This is done the following way:

private LinkedPhoneNumberResponseDto linkTwilioPhoneNumber(String countryCode, String phoneNumber, Account account, Long wabaId) {         TwilioCreateRequestDto body = TwilioCreateRequestDto.builder()                 .configuration(WhatsappTwilioConnectionConfigurationRequestDto.builder()                         .wabaId(wabaId.toString())                         .build())                 .senderId("whatsapp:" + countryCode + phoneNumber)                 .profile(WhatsappTwilioConnectionProfileRequestDto.builder()                         .name(account.getFriendlyName())                         .build())                 .build();         log.info("RequestBody is: {}", body);         log.info("ACC INFO = {}:{}:{}:{}", account.getSid(), account.getAuthToken(), account.getFriendlyName(), account.getStatus());         ResponseEntity<LinkedPhoneNumberResponseDto> res = restClient                 .post()                 .uri("https://messaging.twilio.com/v2/Channels/Senders")                 .headers(headers -> {                     headers.setContentType(MediaType.APPLICATION_JSON);                     headers.setBasicAuth(account.getSid(), account.getAuthToken());                 })                 .body(body)                 .accept(MediaType.ALL)                 .retrieve()                 .toEntity(LinkedPhoneNumberResponseDto.class);         if (res.getStatusCode().is2xxSuccessful()) {             return res.getBody();         } else {             throw new BadRequestException("Something went wrong linking the phone number to Twilio");         }     } 

For some reason, no matter what phone number we use, we always get the validation error.

We've already tried making the request thorugh Postman instead of Twilio's Java library. We've also tried three different phone numbers. Multiple Whatsapp Business Accounts have also been used.

Any help would be appreciated.

public static void uploadVideo(String token, String urlVideo) {     FacebookClient fbClient = new DefaultFacebookClient(token, Version.LATEST);     long scheduledTime = System.currentTimeMillis() / 1000 + 30 * 60;     FacebookType scheduledPostResponse = fbClient.publish("me/videos", FacebookType.class,             Parameter.with("file_url", urlVideo),             Parameter.with("published", false),             Parameter.with("scheduled_publish_time", scheduledTime)); 

I want to post on the site with the condition that I schedule a posting appointment. I used restFB to successfully send the request and receive the ID back, but until now the post does not appear on the page

I have set up application development mode

The result I get from ID

Code

  public String upVideoJson(String token, String mess, String urlVideo, String times) {     String url = "https://graph.facebook.com/v20.0/me/videos";     HttpClient httpClient = HttpClients.createDefault();     String videoId = null;     try {         HttpPost httpPost = new HttpPost(url);         MultipartEntityBuilder builder = MultipartEntityBuilder.create();         String encodedMess = new String(mess.getBytes("UTF-8"), "ISO-8859-1");         builder.addTextBody("access_token", token, ContentType.TEXT_PLAIN);         builder.addTextBody("description", encodedMess, ContentType.create("text/plain", "ISO-8859-1"));         builder.addTextBody("file_url", urlVideo, ContentType.TEXT_PLAIN);         if (StringUtils.hasText(times)) {         builder.addTextBody("scheduled_publish_time", times, ContentType.TEXT_PLAIN);         builder.addTextBody("published", Boolean.toString(false));         }         HttpEntity multipart = builder.build();         httpPost.setEntity(multipart);         HttpResponse response = httpClient.execute(httpPost);         HttpEntity responseEntity = response.getEntity();         String responseString = EntityUtils.toString(responseEntity);         JSONObject jsonResponse = new JSONObject(responseString);         if (jsonResponse.has("id")) {             videoId = jsonResponse.getString("id");         } else {             System.out.println(token);             System.out.println(jsonResponse);         }     } catch (IOException e) {         throw new CustomException();     }     return videoId; } 

I scheduled the post but until now it still hasn't appeared on the Facebook page. When I use the ID to get the permalink_url, only I can see the video, like published = false. Can anyone help me solve the problem?